TSynEdit and TSynAnySyn lazarus / 31-LCL ---------------------------------------------------------------------- JdeHaan · 2018-09-02 11:45 Hi, I have a TSynEdit component and attached to it a TSynAnySyn highlighter. I want to load keywords dynamically at runtime from a file. Looked at SynEdit examples, but somehow I can't get the keywords to be highlighted. They do get highlighted if I put them directly in the Keywords property in the Object Inspector though... Here's my code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ReadKeywords;var  KeywordFile: String;  KeyWordList: TStringList;begin  KeywordFile := ExtractFilePath(Application.ExeName) + 'keywords.txt';  try    KeyWordList := TStringList.Create;    try    KeyWordList.LoadFromFile(KeywordFile);       SynAnySyn.KeyWords.Clear;      SynAnySyn.KeyWords.Assign(KeyWordList);      SynAnySyn.Enabled := True;       SynEdit.Refresh;    except      ShowMessage('Keyword file - keywords.txt - does not exist.');    end;   finally    KeyWordList.Free;    //ShowMessage(SynAnySyn.KeyWords.Text); // shows correctly loaded keywords  end;end;  Any idea what I'm missing here? Thanks OS High Sierra, Laz 1.8.4, FPC 3.04 ---------------------------------------------------------------------- Martin_fr · 2018-09-02 12:38 Try  SynAnySyn.KeyWords := KeyWordList; This will internally assign them. So you still need to free your KeyWordList. Also note, that SynAnySyn does not support utf8. And has the following hardcoded as letters that are treated as words _0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-?! --------------------- If all you need is to highlight group of words, then you can also use TSynEditMarkupHighlightAllMulti (not a highlighter / needs to be added as Markup / sorry no doc avail) ---------------------------------------------------------------------- JdeHaan · 2018-09-02 15:21 Thanks Martin for your suggestion, although it didn't work either. Didn't try your 2nd one BTW. Finally solved it by creating the instance of TSynAnySyn also dynamically and then attach it to SynEdit at runtime in onFormCreate. Don't know why this should have a different result ... anyway it works now. ---------------------------------------------------------------------- Martin_fr · 2018-09-02 16:44 I just did a test (Laz 1.9 svn, Win64) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  l: TStringList;begin  l:= TStringList.Create;  l.Add('abc');  l.Add('def');  SynAnySyn1.KeyWords := l;  l.Free;end; This code works. I did several buttons with different keywords. Have you checked that your file does not have any spaces padding the keywords? To check stringlist (l) items in the debugger: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i l.Flist[0] ---------------------------------------------------------------------- Edson · 2018-09-03 02:52 You can use the highlighter SynFacilSyn: https://github.com/t-edson/SynFacilSyn It's 10 times faster, 10 times more flexible and 10 times more documented than SynAnySyn ---------------------------------------------------------------------- JdeHaan · 2018-09-03 18:57 Thx Edson, I'll study your component. I indeed did find SynAnySyn quite slow...