[Lazarus] Object free itself?

Mattias Gaertner nc-gaertnma at netcologne.de
Fri May 16 01:28:21 CEST 2008


On Thu, 15 May 2008 16:41:00 -0400
Lee Jenkins <lee at datatrakpos.com> wrote:

> Mattias Gaertner wrote:
> > On Thu, 15 May 2008 21:25:38 +0200
> > Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
> > 
> >> [...]
> >>> When the form is closed, the controller is notified and need to 1)
> >>> free the form 2) free the model/object and 3) free itself.
> > 
> > Ehm. Please explain 'when the form is closed'.
> > 
> > A lcl form is not a single object.
> > 
> 
> Granted.  What I'm trying to do is control the creation of the form
> and the object that the form is a view of from within the controller.
> 
> 1. Controller is created.
> 2. Controller create the object/model.
> 3. When the form is closed the controller destroys the form and the
> model and then frees itself.
> 
> Currently, I'm hooking into the form's Onclose event with a method in
> the controller with the same signature.  When the method is fired,
> the controller frees the form and the model/object then frees itself.
> 
> I guess I could create the controller from within the form/view, but
> that seems to defeat the idea of MVC.

Please keep in mind, that you can not free a control, during an event
for this control. (Some events on some widgetsets allow this, but this
can change in future so I won't count on it). But you can free it later,
using Application.ReleaseComponent(AControl).

For example:

  Form1.Close;
  Application.ReleaseComponent(Form1);
  Form1:=nil;

The Form1 will continue existing and will be freed on next idle.


Mattias



More information about the Lazarus mailing list