Recent

Author Topic: [SOLVED] string case label not colored  (Read 924 times)

440bx

  • Hero Member
  • *****
  • Posts: 4731
[SOLVED] string case label not colored
« on: February 24, 2024, 08:25:54 pm »
Hello,

It can be seen in the following code that case labels are not colored according to their type yet, they are in other statements (such as assigment).  Sample code (copy/paste into your version of Lazarus):
Code: Pascal  [Select][+][-]
  1. program CaseT;
  2.  
  3. function test() : boolean;
  4. var
  5.   s      : string;
  6.  
  7. begin
  8.   result := FALSE;
  9.  
  10.   s      := '-1';     { strings are colored in the assignment statement       }
  11.   s      := '-2';
  12.  
  13.   case ParamStr(1) of
  14.     '-1' : ;          { label not colored as string                           }
  15.     '-2' : ;
  16.  
  17.     otherwise
  18.     begin
  19.       { note that '-1' and '-2' are colored in the writeln statement          }
  20.  
  21.       writeln('neither ', '-1', ' nor ', '-2', ' entered');
  22.     end;
  23.   end;
  24.  
  25.   result := TRUE;
  26. end;
  27.  
  28. function test2() : boolean;
  29. var
  30.   i       : integer = 0;
  31.  
  32. begin
  33.   result  := FALSE;
  34.  
  35.   i := 1;             { numbers are colored in the assignment statement       }
  36.   i := 2;
  37.  
  38.   i := ParamCount();
  39.  
  40.   case i of
  41.     1 : ;             { label not colored as number                           }
  42.     2 : ;
  43.  
  44.     otherwise
  45.     begin
  46.       { note that 1 and 2 are colored in the writeln statement                }
  47.  
  48.       writeln('ParamCount may only be ', 1, ' or ', 2);
  49.     end;
  50.   end;
  51.  
  52.   result  := TRUE;
  53. end;
  54.  
  55.  
  56. begin
  57.   test ();
  58.   test2();
  59. end.                            

The attachment shows the lack of coloring in the fixes branch of Lazarus (v3.1)

Not sure if the lack of coloring is a bug but, it seems reasonable to expect the case labels to be colored according to their type  as they are in other statements.

Useful comments welcome.
« Last Edit: February 24, 2024, 09:28:11 pm by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: string case label not colored
« Reply #1 on: February 24, 2024, 08:45:20 pm »
Of course it looks different here ...
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10552
  • Debugger - SynEdit - and more
    • wiki
Re: string case label not colored
« Reply #2 on: February 24, 2024, 08:55:38 pm »
My first guess would be incorrect config... So lets check that.

Tools > Options > Editor > Display > Color

This page has a tree with colors, (when selecting "ObjectPascal" in the toolbar / selected by default)  the first section in that tree is "ObjectPascal" and it has an entry called "Case label".

On my default 3.0 test install, all colors for "case label" are unset => and so they do nothig => and case labels show the underlying normal color.



"Case label" can either be used to apply an attribute otherwise not used (maybe underline, maybe frame), or background color.

Or it can be used  to mix colors using the alpha setting.

Or it can be used to change color, but for identifier labels only. For that priorities of string/number color have to be set higher than "Case label".

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10552
  • Debugger - SynEdit - and more
    • wiki
Re: string case label not colored
« Reply #3 on: February 24, 2024, 09:03:28 pm »
As a bit of maybe useful info....

Colors (in the language section, e.g. "objectpascal") that are not explicitly set fall back to "default text"

Except:
Colors that (in the color editor) either offer an alpha channel, or on the font-attributes (bold...) have "on/off/invert" => those are modifier colors. The underlying code/text should already be covered by another color (in your case string or number), and can be further modified.
(those work like the "bracket highlight" or "selection" color, and all other colors that are applied on top of Pascal colors)

440bx

  • Hero Member
  • *****
  • Posts: 4731
Re: string case label not colored
« Reply #4 on: February 24, 2024, 09:10:32 pm »
Thank you KodeZwerg and thank you Martin.

Martin your posts solved the problem.  I changed the "case label" foreground setting to "not modified" and that did the trick :)

Also, the additional info, is important to be aware of.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018