Recent

Author Topic: [SOLVED] Setting TLabel caption causes crash at run  (Read 639 times)

GeneCode

  • New Member
  • *
  • Posts: 25
  • What is the cost of lies?
[SOLVED] Setting TLabel caption causes crash at run
« 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?  %)
« Last Edit: May 11, 2021, 05:03:05 am by GeneCode »
Windows 10
Lazarus 1.8.4

GeneCode

  • New Member
  • *
  • Posts: 25
  • What is the cost of lies?
Re: Setting TLabel caption causes crash at run
« Reply #1 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.
Windows 10
Lazarus 1.8.4

 

TinyPortal © 2005-2018