Recent

Author Topic: Falling back to 2.2.6  (Read 1261 times)

Slyde

  • Full Member
  • ***
  • Posts: 152
Falling back to 2.2.6
« on: January 07, 2024, 04:00:32 pm »
I've been working on a personal project that was started with 2.2.4.  When I switched to 2.2.6, nothing broke.  All my code worked as expected.  However, when I installed 3.0.0, I lost a really important aspect of my program. 

It's just a trivia application, where the user selects an answer and then verifies it.  On a wrong answer, the user-selected answer gets a red background and the correct answer lights up green.  That doesn't happen with 3.0.0.  The procedure itself runs flawlessly through all of its code.  But it fails to change the label color.  So I switched back to 2.2.6 and all is well, again.

Lazarus 2.2.6 was a really nice release anyway.  So I'll just stick with it until the bugs are gone from 3.0.0.
Linux Mint 21.3
Lazarus 3.0

wp

  • Hero Member
  • *****
  • Posts: 11924
Re: Falling back to 2.2.6
« Reply #1 on: January 07, 2024, 04:19:45 pm »
What is your operating system?

Slyde

  • Full Member
  • ***
  • Posts: 152
Re: Falling back to 2.2.6
« Reply #2 on: January 07, 2024, 04:26:25 pm »
OS: Linux Mint 21.2
Linux Mint 21.3
Lazarus 3.0

wp

  • Hero Member
  • *****
  • Posts: 11924
Re: Falling back to 2.2.6
« Reply #3 on: January 07, 2024, 05:31:28 pm »
I can confirm this on Manjaro. Seems to be a bug for me since the Label is custom-drawn.

But regarding colors there is always an uncertainty depending on the widgetset. Although there is a Color property, its value is often neglected by the widgetset.

Therefore, if colors are important in your application, you simply should draw the text by yourself rather than relying on a component. For example, you could use a TPaintbox instead of a TLabel, and in its OnPaint event you draw the text:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
  9.  
  10. type
  11.   TResult = (UndefinedResult, CorrectResult, WrongResult);
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     Button2: TButton;
  18.     PaintBox1: TPaintBox;
  19.     procedure Button1Click(Sender: TObject);
  20.     procedure Button2Click(Sender: TObject);
  21.     procedure PaintBox1Paint(Sender: TObject);
  22.   private
  23.     SavedResult: TResult;
  24.     procedure ShowResult(AResult: TResult);
  25.  
  26.   public
  27.  
  28.   end;
  29.  
  30. var
  31.   Form1: TForm1;
  32.  
  33. implementation
  34.  
  35. {$R *.lfm}
  36.  
  37. { TForm1 }
  38.  
  39. procedure TForm1.ShowResult(AResult: TResult);
  40. begin
  41.   SavedResult := AResult;
  42.   Paintbox1.Invalidate;
  43. end;
  44.  
  45. procedure TForm1.PaintBox1Paint(Sender: TObject);
  46. const
  47.   COLORS: array[TResult] of TColor = (clNone, clGreen, clRed);
  48.   MSG: array[TResult] of string = ('', 'Correct', 'Wrong');
  49. begin
  50.   Paintbox1.Canvas.Font.Color := COLORS[SavedResult];
  51.   Paintbox1.Canvas.TextOut(0, 0, MSG[SavedResult]);
  52. end;
  53.  
  54. procedure TForm1.Button1Click(Sender: TObject);
  55. begin
  56.   ShowResult(CorrectResult);
  57. end;
  58.  
  59. procedure TForm1.Button2Click(Sender: TObject);
  60. begin
  61.   ShowResult(WrongResult);
  62. end;
  63.  
  64. end.
 

Slyde

  • Full Member
  • ***
  • Posts: 152
Re: Falling back to 2.2.6
« Reply #4 on: January 07, 2024, 06:07:31 pm »
I appreciate that, wp.  I've never used TPaintBox for anything, but clearly see its upside.  Thanks for the heads-up.
Linux Mint 21.3
Lazarus 3.0

wp

  • Hero Member
  • *****
  • Posts: 11924
Re: Falling back to 2.2.6
« Reply #5 on: January 07, 2024, 06:14:02 pm »
Or if you refrain from custom-painting, you could also use ("abuse") a TPanel: it has a Caption, which nicely can be recolored, you can even left/right/top/bottom-align the caption, or center it. Just simply switch the borders off (BevelInner and BevelOuter) and make sure that the panel's ParentColor is true.

I can confirm this on Manjaro.
Very strange: repeating this in Mint, and now in Manjaro again, the label color does change!

PawelO

  • New Member
  • *
  • Posts: 16
    • Polish railway traffic and interlocking simulator developed with Lazarus
Re: Falling back to 2.2.6
« Reply #6 on: March 01, 2024, 06:07:16 pm »
I suppose you have already solved this, but...

https://wiki.lazarus.freepascal.org/Lazarus_3.0_release_notes#TLabel.Transparent.2C_.Color_and_.ParentColor_changes

Set TLabel.Transparent to False and it will be colored.

 

TinyPortal © 2005-2018