EControl Ltd. Forum Index EControl Ltd.
VCL libraries and software support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Setting the syntax highlighter at runtime

 
Post new topic   Reply to topic    EControl Ltd. Forum Index -> EControl Syntax Editor
View previous topic :: View next topic  
Author Message
jfcarbel



Joined: 13 Jun 2006
Posts: 27

PostPosted: Thu Jun 15, 2006 6:06 am    Post subject: Setting the syntax highlighter at runtime Reply with quote

Here is what I tried, but when I set the text from the loaded file into the memo, it does not display any syntax highlighting.

In addition to the code below I also tried putting a SyntAnalyzer on my form and linking it to the SyntaxMenu via its SyntaxAnalyzer property. In addition I sent the LexerName of SyntAnalyzer to 'HTML documents' to force it to format and highlight the HTML text, but this still did not work.

NOTE: LexLib.LXL is in this applications directory.

Code:
procedure TFormMain.FormCreate (Sender: TObject);

procedure LoadFile(Comp: TLoadableComponent; const AFileName: string);
begin
  if FileExists(AFileName) then
    try
      Comp.LoadFromFile(AFileName);
    except
      Application.HandleException(Self);
  end;
end;
begin
  LoadFile(SyntaxManager1, ExtractFilePath(Application.ExeName) + 'LexLib.LXL');
  LoadFile(SyntStyles1, ChangeFileExt(Application.ExeName, '.ecs'));
end;


// Code in my open file dialog
OD.Filter := SyntaxManager1.GetFilesFilter;
if od.Execute then
begin
  SyntaxManager1.CurrentLexer :=     SyntaxManager1.AnalyzerForFile(od.FileName);
  Parse(od.FileName); // parses the HTML and then displays it in the SyntaxMemo
end;
Back to top
View user's profile Send private message
jfcarbel



Joined: 13 Jun 2006
Posts: 27

PostPosted: Thu Jun 15, 2006 6:10 am    Post subject: Reply with quote

Was able to get this to work, but not the way I would want (see below)

It would much easier with the below methods. This would allow us to programatically change the SyntaxAnalyzer and also turn off code folding which I do not want.

Code:
SyntaxManager1.CurrentLexer := SyntaxManager1.AnalyzerForType('HTML documents');
SyntaxManager1.CurrentLexer.CodeFolding := False;



Was finally able to get it to work by using the below code and saving down a new version of LexLib.LXL where I removed the 'HTML with scripts'. The problem was that the AnalyzerForFile method was defaulting to 'HTML with scripts' rather than the 'HTML documents' one I wanted.

Code:
s := ExtractFilePath(Application.ExeName) + 'LexLib.LXL';
if FileExists(s) then
SyntaxManager1.LoadFromFile(s);

SyntaxManager1.CurrentLexer := SyntaxManager1.AnalyzerForFile(od.FileName);
SyntaxMemo1.SyntaxAnalyzer := SyntaxManager1.CurrentLexer;


I realized I can also do this, but a AnalyzeForType would be much better since indexes will change if more Lexers are added:

Code:
SyntaxMemo1.SyntaxAnalyzer := SyntaxManager1.Analyzers[10];
Back to top
View user's profile Send private message
jfcarbel



Joined: 13 Jun 2006
Posts: 27

PostPosted: Thu Jun 15, 2006 6:10 am    Post subject: Reply with quote

Posted by: econtrol (IP Logged)
Date: May 31, 2006 11:48AM

OK.

I shall implement TSyntaxManager.FindAnalyzer(const LexerName: string);

Michael.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    EControl Ltd. Forum Index -> EControl Syntax Editor All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group