Lazarus

Programming => LCL => Topic started by: GeneCode on May 11, 2021, 04:20:26 am

Title: [SOLVED] Setting TLabel caption causes crash at run
Post by: GeneCode on May 11, 2021, 04:20:26 am
This is weird.
I have a TValueListEditor and Event OnSelection setup.

Here is the onEvent function:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.AppTableSelection(Sender: TObject; aCol, aRow: Integer);
  2. begin
  3.   WriteLn(IntTostr(aRow));
  4.   WriteLn(appsArray[aRow]);
  5. end;

Work ok, when I select a row on the ValueListEditor, I get the row index and the value of that array at that index. But when I input a TLabel with name appLabel, and I add the code to set the text,

Code: Pascal  [Select][+][-]
  1. appLabel.Caption := 'test';
in the event method above, it immediately crash when run.

ERROR:
Project *** raises exception class External SIGSEGV
In file control.inc

Any idea why?  %)
Title: Re: Setting TLabel caption causes crash at run
Post by: GeneCode on May 11, 2021, 04:27:39 am
Ok found the issue. lol

Turns out this event is called at formcreate, and that time the label is not created yet (i guess).
So i use a boolean flag to set to true only after formActivate.

And in the onSelection event, do (pseudocode)

if (canRun) {
  set label text.
}

Then it is ok and no more crashing and works as expected.
TinyPortal © 2005-2018