Recent

Author Topic: Help with Script in Report for font change  (Read 3211 times)

Ever

  • Jr. Member
  • **
  • Posts: 71
Help with Script in Report for font change
« on: August 22, 2023, 04:03:35 pm »
Greetings to all

     I turn to you for help with the following:

     I need to change the style of a font based on the value of a table field, if that field contains the value of 'A', then the font should be strikethrough and if not, it should be normal.

     I have tried placing the following script in the memo component that I want to affect, but it gives me an error indicating that the property does not exist.


Code: Pascal  [Select][+][-]
  1. if [mdmovi."movi_anulado"]='A' then
  2.    Font.Style.fsStrikeOut:=True
  3. else
  4.    Font.Style.fsStrikeOut:=False
  5.  

  Additional to this, I also need to change the font color for the same component.

   Thank you for any support you can give me.

alpine

  • Hero Member
  • *****
  • Posts: 1297
Re: Help with Script in Report for font change
« Reply #1 on: August 22, 2023, 07:23:57 pm »
I'm afraid it is not possible. Scripts in LazReport are very basic and nearly reduced to simple expressions.

You can try using "Highlight attributes" button for a memo, but it can change only the color, bold, italic, and underline, no strike-out.
 
You can also try writing a OnEnterRect handler, see https://forum.lazarus.freepascal.org/index.php/topic,31416.msg201216.html#msg201216, check the current value of the DB Field and try changing (View as TfrMemoView).Font.Style value. Not sure it works, though.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Ever

  • Jr. Member
  • **
  • Posts: 71
Re: Help with Script in Report for font change
« Reply #2 on: August 22, 2023, 07:39:11 pm »
Thanks for answering

    I was able to partially solve the problem, but indeed, as you say, it doesn't support strike-out, so I just changed the color to a gray one. But if I managed to place according to the value of a field in the database, that the income or deposits are green and the withdrawals are red.

   The code used is the following written in the Script property of the object, of course, it looks a bit more complex since according to a variable I invert the green and red colors.
Code: Pascal  [Select][+][-]
  1. if [mdmovi."movi_anulado"]='A' then
  2. begin
  3.    Fontcolor:=clGray;
  4.    FontStyle:=3;
  5. end
  6. else
  7. begin
  8.   if [mdmovi."movi_tip"]=1 then
  9.   begin
  10.     if Color_Ingreso='clGreen' then
  11.     begin
  12.        FontColor:= clGreen;
  13.        FontStyle:=0;
  14.     end
  15.     else
  16.     begin
  17.        FontColor:=clRed;
  18.        FontStyle:=0;
  19.     end
  20.   end
  21.   else
  22.   begin
  23.     if  Color_Egreso='clRed' then
  24.     begin
  25.       FontColor:=clRed;
  26.       FontStyle:=0;
  27.     end
  28.  
  29.     else
  30.     begin
  31.       FontColor:= clGreen;
  32.       FontStyle:=0;
  33.     end
  34.   end
  35. end  
  36.  

   I also investigated (View as TfrMemoView) but it is not possible either

jesusr

  • Sr. Member
  • ****
  • Posts: 496
Re: Help with Script in Report for font change
« Reply #3 on: August 24, 2023, 02:58:58 am »
Apparently, you found that font styles *are* supported in report scripts as it seems you found in your last script.

The interpreter don't support classes or advanced features, but it does support a good set of what plain pascal can  do. Just it is able to pick an statement in the script editor box, but if the statement is a begin end; block it then can include any number of statements.

If you want to know what report features are exposed to the script, check the document at lazreport/doc/fr_eng.pdf

Ever

  • Jr. Member
  • **
  • Posts: 71
Re: Help with Script in Report for font change
« Reply #4 on: August 24, 2023, 03:07:22 am »
Indeed it is so, but not all styles are accepted. I was also able to change the color of the font, which was one of the client's requirements. See part of what is required in fr_eng.pdf.

Thanks for the support

madref

  • Hero Member
  • *****
  • Posts: 1078
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Help with Script in Report for font change
« Reply #5 on: September 19, 2023, 11:42:22 pm »
Have you tried
Code: Pascal  [Select][+][-]
  1. Font.Style := 'fsStrikeOut';


Because I had something simular.
See https://forum.lazarus.freepascal.org/index.php/topic,64603.0.html
« Last Edit: September 19, 2023, 11:44:26 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7
Lazarus 3.99 (Lazarus 3.99 (rev main_3_99-2668-g6b352d830e) FPC 3.3.1 x86_64-darwin-cocoa)

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

Ever

  • Jr. Member
  • **
  • Posts: 71
Re: Help with Script in Report for font change
« Reply #6 on: September 19, 2023, 11:56:55 pm »
Greetings

    Yes, I actually did that test and it gave a variable not found error.

madref

  • Hero Member
  • *****
  • Posts: 1078
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Help with Script in Report for font change
« Reply #7 on: September 20, 2023, 12:06:46 am »
and if you just try
Code: Pascal  [Select][+][-]
  1. Font := 'fsStrikeOut';
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7
Lazarus 3.99 (Lazarus 3.99 (rev main_3_99-2668-g6b352d830e) FPC 3.3.1 x86_64-darwin-cocoa)

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

Ever

  • Jr. Member
  • **
  • Posts: 71
Re: Help with Script in Report for font change
« Reply #8 on: September 24, 2023, 05:33:45 pm »
Unfortunately it doesn't work either.

Reading the information from the fr_eng.pdf file, it does not indicate that it is possible for that case

thanks for the support and interest

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: Help with Script in Report for font change
« Reply #9 on: September 25, 2023, 12:31:27 pm »
This can be done only beforehand you need to make a change in the LazReport code, as it currently does not support strikethrough in the script - you can find the patch here: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40521 
   
Then you create a script similar to this one:
Code: Pascal  [Select][+][-]
  1. if ([LINE#] mod 6) = 0 then
  2. begin
  3.   FontStyle := 0; //normal
  4.   FontColor := clRed;
  5.   FillColor := clWhite;
  6. end
  7. else if ([LINE#] mod 6) = 1 then
  8. begin
  9.   FontStyle := 15; //all styles = 1(italic) + 2(bold) + 4(undeline) + 8(strikeout)
  10.   FontColor := clRed;
  11.   FillColor := clWhite;
  12. end
  13. else if ([LINE#] mod 6) = 2 then
  14. begin
  15.   FontStyle := 1; //italic
  16.   FontColor := clGreen;
  17.   FillColor := clWhite;
  18. end
  19. else if ([LINE#] mod 6) = 3 then
  20. begin
  21.   FontStyle := 2; //bold
  22.   FontColor := clBlue;
  23.   FillColor := clWhite;
  24. end
  25. else if ([LINE#] mod 6) = 4 then
  26. begin
  27.   FontStyle := 4; //underline
  28.   FontColor := clWhite;
  29.   FillColor := clBlack;
  30. end
  31. else
  32. begin
  33.   FontStyle := 8; //strikeout
  34.   FontColor := clYellow;
  35.   FillColor := clNavy;
  36. end;
  37.  
  38.  
Best regards / Pozdrawiam
paweld

Ever

  • Jr. Member
  • **
  • Posts: 71
Re: Help with Script in Report for font change
« Reply #10 on: September 25, 2023, 01:47:55 pm »
Indeed I corrected the code in the lr_utils.pas file and it worked perfectly

  Thank you very much for taking the time to support me.

 

TinyPortal © 2005-2018