Recent

Author Topic: [SOLVED] CreateForm Error  (Read 2209 times)

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
[SOLVED] CreateForm Error
« on: January 01, 2014, 10:53:57 pm »
I  am using lazarus 1.2RC1 on Windows 8.0.

I recently installed the free version of Avast (virus checker). Since then all of my code that creates a new form fails after closing the new form and then trying to create it again.

I have now shutdown Avast, but the error remains.

The error message is:
--------------------
Project project1 raised exception class 'External: SIGSEGV'.

At address 403D34
--------------------

The attachment is a simple project that always fails when form2 is opened a second time.

Could someone please check it on R1.2RC1?
« Last Edit: January 02, 2014, 10:39:33 am by Windsurfer »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: CreateForm Error
« Reply #1 on: January 01, 2014, 11:13:15 pm »
Code: [Select]
..
    if Form2 = nil then Application.CreateForm(TForm2, Form2);
    Form2.Show;
..

Code: [Select]
Procedure Tform2.Formclose(Sender: TObject; Var CloseAction: TCloseAction);
  Begin
    CloseAction := caFree;
  End;

The second time you call it, Form2 is not nil and it points at the destroyed form. It should give you a nice SIGSEGV

You need to set Form2 tol nil when you destroy it.

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: CreateForm Error
« Reply #2 on: January 01, 2014, 11:27:05 pm »
Thanks engkin,

I added Form2 := nil;

after

CloseAction := caFree;

and it worked. I assume that my previous testing was incomplete.

My reason for creating forms dynamically is to reduce memory footprint. I used to program with if form2 <> nil then etc.. and avoided the problem without knowing it.
« Last Edit: January 02, 2014, 11:33:48 am by Windsurfer »

 

TinyPortal © 2005-2018