Question

I have a main form with a TMainMenu and when I click on a submenu I have to show a new form. This is the code:

procedure TForm1.MenuItem12Click(Sender: TObject);
var Form2 : TForm2;
begin
 Form2 := TForm2.Create(nil);
 Form2.Show;
end; 

And the in the Uses I put Unit2, which is the name of the 2nd form's unit. When I run the program, It correctly opens the Form 2. By the way, when I close the program I have a SIGSEGV error with Lazarus.

How could I avoid it? I have used this code too in other programs, but I had no problems. Both forms are setted on FormStyle := fsNormal;

enter image description here

Was it helpful?

Solution 2

The only problem with the code you show is that you leak the form. You create it with no owner, and nothing else destroys it.

The obvious way to deal with that is to own it:

Form2 := TForm2.Create(Self);

This may not fix your error but it is the only thing wrong with the code you showed.

OTHER TIPS

Most likely causes is a problem in the OnFormClose event of Form2 -OR- a flaw in the destructor code of any objects on Form2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top