Board index » delphi » Cannot Free MDI Child if add several labels?!

Cannot Free MDI Child if add several labels?!

I would like to be able to close a MDI child form by clicking on a
button.  Sounds easy but I can't do it.  Application will either crash
with an access violation or an EAbstractError when I do following
steps:

1.  Create two forms.  Main MDI form and MDI child.  
2.  Add Free instruction to child form's Close event to remove form
memory when close form.
3.  Add button to child form and add Close instruction to onclick
event

App works fine at this stage - clicking on button will close child
form; until I add 20x labels to child form.  Then app will crash.

An OK button to close a form must be such a basic function that I must
be doing something fundamentally wrong.

Please help.

Thanks,

Nigel Patmore.

 

Re:Cannot Free MDI Child if add several labels?!


You are not allowed to call Free in an event handler of an object. That is
why Borland introduced the Release method for forms.

ps. As an alternative you could set CloseAction to caFree in the OnClose
handler.

Quote
"Nigel Patmore" <ni...@ecom.co.nz.NOSPAM> wrote in message

news:3bba6a99.418530324@EServer...
Quote
> I would like to be able to close a MDI child form by clicking on a
> button.  Sounds easy but I can't do it.  Application will either crash
> with an access violation or an EAbstractError when I do following
> steps:

> 1.  Create two forms.  Main MDI form and MDI child.
> 2.  Add Free instruction to child form's Close event to remove form
> memory when close form.
> 3.  Add button to child form and add Close instruction to onclick
> event

> App works fine at this stage - clicking on button will close child
> form; until I add 20x labels to child form.  Then app will crash.

> An OK button to close a form must be such a basic function that I must
> be doing something fundamentally wrong.

> Please help.

> Thanks,

> Nigel Patmore.

Re:Cannot Free MDI Child if add several labels?!


Did you close the right form with
CLOSE button ?

Did you change formstyle of forms to
fsMDIform/fsMDIchild ?

If main form is FORM1,and child form is
FORM2 then code for button in FORM2 is:

form2.close;

Also.in child from add:

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree
end;

And this MUST work !!!

Re:Cannot Free MDI Child if add several labels?!


I have basically the same problem - I am doing exactly as you describe here
but still get the same errors - see new post dated 2 Apr for details.

Paul Scott

Quote
"nihilist" <noth...@haha.com> wrote in message

news:3bbc7aea.2028834@news.tel.hr...
Quote
> Did you close the right form with
> CLOSE button ?

> Did you change formstyle of forms to
> fsMDIform/fsMDIchild ?

> If main form is FORM1,and child form is
> FORM2 then code for button in FORM2 is:

> form2.close;

> Also.in child from add:

> procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
> begin
> action:=cafree
> end;

> And this MUST work !!!

Other Threads