Recent

Author Topic: Problem with reading TSynFacilSyn color values from an inifile  (Read 342 times)

maurobio

  • Jr. Member
  • **
  • Posts: 53
Problem with reading TSynFacilSyn color values from an inifile
« 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!
UCSD Pascal / Burroughs 6700 / Master Control Program
Lazarus 2.0.2/2.0.4 - FPC 3.0.4 on GNU/Linux Mint 13 ("Maya"), Windows XP SP3, Windows 7 Professional, Windows 10 Home

Edson

  • Hero Member
  • *****
  • Posts: 1055
Re: Problem with reading TSynFacilSyn color values from an inifile
« Reply #1 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?
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

maurobio

  • Jr. Member
  • **
  • Posts: 53
Re: Problem with reading TSynFacilSyn color values from an inifile
« Reply #2 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,
UCSD Pascal / Burroughs 6700 / Master Control Program
Lazarus 2.0.2/2.0.4 - FPC 3.0.4 on GNU/Linux Mint 13 ("Maya"), Windows XP SP3, Windows 7 Professional, Windows 10 Home

maurobio

  • Jr. Member
  • **
  • Posts: 53
Re: Problem with reading TSynFacilSyn color values from an inifile
« Reply #3 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,
UCSD Pascal / Burroughs 6700 / Master Control Program
Lazarus 2.0.2/2.0.4 - FPC 3.0.4 on GNU/Linux Mint 13 ("Maya"), Windows XP SP3, Windows 7 Professional, Windows 10 Home

Edson

  • Hero Member
  • *****
  • Posts: 1055
Re: Problem with reading TSynFacilSyn color values from an inifile
« Reply #4 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.
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

maurobio

  • Jr. Member
  • **
  • Posts: 53
Re: Problem with reading TSynFacilSyn color values from an inifile
« Reply #5 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,
UCSD Pascal / Burroughs 6700 / Master Control Program
Lazarus 2.0.2/2.0.4 - FPC 3.0.4 on GNU/Linux Mint 13 ("Maya"), Windows XP SP3, Windows 7 Professional, Windows 10 Home

Edson

  • Hero Member
  • *****
  • Posts: 1055
Re: Problem with reading TSynFacilSyn color values from an inifile
« Reply #6 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
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

maurobio

  • Jr. Member
  • **
  • Posts: 53
Re: Problem with reading TSynFacilSyn color values from an inifile
« Reply #7 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,
UCSD Pascal / Burroughs 6700 / Master Control Program
Lazarus 2.0.2/2.0.4 - FPC 3.0.4 on GNU/Linux Mint 13 ("Maya"), Windows XP SP3, Windows 7 Professional, Windows 10 Home