Lazarus

Programming => Packages and Libraries => SynEdit => Topic started by: maurobio on November 07, 2019, 12:45:44 pm

Title: Problem with reading TSynFacilSyn color values from an inifile
Post by: maurobio on November 07, 2019, 12:45:44 pm
Dear ALL,

I am using the (really superb!) TSynFacilSyn component for custom syntax highlighting and have stumbled upon a problem when attemping to read the keyword colors from a Inifile.

To read the color value (or use a default color in case there is no color value saved into the Inifile), I have the line:

KeywordColor := IniFile.ReadInteger('Colors', 'Keywords', clRed);

Then I attribute the value read from the inifile to the highlighter (obviously it has been already declared):

Hlt.tkKeyword.Foreground := KeywordColor;

Finally, I force a redraw of the TSynEdit control to which the highlighter has been assigned:

SynEdit1.Invalidate;

But none of the above works. The keywords kept appearing in the default color (green), even if they are correctly saved to and read from the inifile as red (color value 255).

Can someone help me?

Thanks in advance!
Title: Re: Problem with reading TSynFacilSyn color values from an inifile
Post by: Edson on November 08, 2019, 12:29:32 am
Hi.

Have you tested just doing:

Code: Pascal  [Select][+][-]
  1. Hlt.tkKeyword.Foreground := clRed;

Can you share a sample project showing the problem?
Title: Re: Problem with reading TSynFacilSyn color values from an inifile
Post by: maurobio on November 08, 2019, 12:36:52 am
@Edson,

Yes, I tested it that way.

But I will soon provide a sample project to make things clearer.

Thanks a lot for you assistance.

Cheers,
Title: Re: Problem with reading TSynFacilSyn color values from an inifile
Post by: maurobio on November 08, 2019, 01:33:00 am
@Edson,

Here is a sample project that reproduces the problem with reading a color value from an inifile and attributing it to a TSynFacilSyn highlighter.

Cheers,
Title: Re: Problem with reading TSynFacilSyn color values from an inifile
Post by: Edson on November 08, 2019, 03:39:43 am
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   IniFile := TIniFile.Create('test.ini');
  4.   // This does not work, the default color is not used, and the color saved to the Inifile is not read either
  5.   KeywordColor := IniFile.ReadInteger('Colors', 'Keywords', clBlue);
  6.   Hlt := TSynFacilSyn.Create(self);
  7.   SynEdit1.Highlighter := Hlt;
  8.   Hlt.LoadFromFile('ObjectPascal.xml');
  9.   SynEdit1.Lines.LoadFromFile('ObjectPascal_sample.txt');
  10. end;

This doesn't work because you are not changing the value of the attribute. If you add these lines to the end:

Code: Pascal  [Select][+][-]
  1.   Hlt.tkKeyword.Foreground := KeywordColor;
  2.   SynEdit1.Invalidate;
  3.  

It works OK.
Title: Re: Problem with reading TSynFacilSyn color values from an inifile
Post by: maurobio on November 08, 2019, 10:13:26 am
@Edson,

Yes, that's it!

It looks pretty obvious now. I became tangled by this foolish problem in the code of my application, which reads/writes a lot more from/to inifiles. It works great now!

Thanks a lot for your help.

Best regards,
Title: Re: Problem with reading TSynFacilSyn color values from an inifile
Post by: Edson on November 09, 2019, 03:57:45 pm
If you are looking for changing and storing properties to disk; maybe you can use my other library: https://github.com/t-edson/MiConfig
Title: Re: Problem with reading TSynFacilSyn color values from an inifile
Post by: maurobio on November 09, 2019, 05:17:33 pm
@Edson,

Great, I'll take a look into it. Hope it will as useful as your really superb TSynFacilSyn component, which is truly perfect!

Cheers,
TinyPortal © 2005-2018