Hi, I'm new to the forum and to FPC programming. Have used C# years ago.
Running the following code works fine the first time. The second time I get:
Project Buildings raised exception class 'External: SIGSEGV'.
In file 'control.inc' at line 3620:
len := GetTextLen;
I assume this is a memory / Freeing problem? Please help..
procedure TMainForm.lbBuildingsDblClick(Sender: TObject);
var
selectedBuilding: TBuilding;
begin
selectedBuilding := TBuilding(lbBuildings.Items.Objects[lbBuildings.ItemIndex]);
if not Assigned(editForm) then
editForm := TFormBuilding.Create(Self);
editForm.Building := selectedBuilding;
editForm.ShowModal;
//building has been edited, replace the list item string, leaving the object untouched
lbBuildings.Items[lbBuildings.ItemIndex] := selectedBuilding.Name;
end;
The error occurs when the line " editForm.Building := selectedBuilding;" is executed.
I've discovered that if I add a
FreeAndNil(editForm);
after ShowModal returns, it works as I was expecting, no error.
But I thought that one was able to reuse forms?
Any ideas?
Thank you!