(1) is incorrect. When a component is freed, its owner is notified and the
component is removed from the owner's list of child components. Having said
that, if your code will be freeing the component explicitly, then there is
no reason to assign the component an owner. Re, the following line in
TComponent.Destroy.
if FOwner <> nil then FOwner.RemoveComponent(Self);
(2) There is no reason why a dynamic method cannot free an object.
Afterall, free simply checks the pointer value and if it is not Nil, calls
the destructor (which is a virtual method).
The only trap is after the method returns, the calling method (perhaps
another method in the same object) then tries to dereference self or an
implicit dereference to self (eg. to access variables in the object, call a
virtual method).
If this is your problem, then create a worker thread of idle priority - this
ensures that it will not get scheduled as long as the main thread is
running. Pass a reference to the component to the worker thread. When the
worker thread gets scheduled, it frees the component.
Regards,
Dennis.
----- Original Message -----
From: "Stephen Bertram" <[EMAIL PROTECTED]>
To: "NZ Borland Developers Group - Delphi List" <[EMAIL PROTECTED]>
Sent: Friday, March 19, 2004 10:11 AM
Subject: RE: [DUG] Self Freeing
My understanding is:
1. If a component has an owner then the owner will try to free it during its
destroy method leading to an access violation if it is freed elsewhere. So
if you are explicitly freeing it create it with Create(Nil). N.B. for
newcomers - this is totally different to specifying the Parent.
2. There is no reason why the method assigned to OnExit can't be a static
method.
Stephen
-----Original Message-----
From: Paul Mckenzie [mailto:[EMAIL PROTECTED]
Sent: Friday, 19 March 2004 9:06 a.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Self Freeing
I like having an Owner - (But could if necessary have no Owner).
I want the Component initiate the free in a non-static method (eg OnExit,
OnClick)
No longer referring to the variable - that is not a problem.
This is all just in the main (only) thread.
Regards
Paul McKenzie
Analyst Programmer
SMSS Ltd.
----- Original Message -----
From: Stephen Bertram <mailto:[EMAIL PROTECTED]>
To: NZ Borland Developers Group - Delphi <mailto:[EMAIL PROTECTED]> List
Sent: Friday, March 19, 2004 8:46 AM
Subject: RE: [DUG] Self Freeing
AFAIK there is no problem executing Self.Free on the following conditions:
1. The object does not have an owner
2. The Self.Free statement is in a static method
3. The object is not later refered to from the generating program - either
the object is not assigned to a variable or the variable is never accessed
after the method call that results in the Free.
The real question is why you would want to do this outside a thread?
Stephen
-----Original Message-----
From: Stacey Verner [mailto:[EMAIL PROTECTED]
Sent: Thursday, 18 March 2004 4:46 p.m.
To: NZ Borland Developers Group - Delphi List
Subject: RE: [DUG] Self Freeing
In the case of a form override OnClose and set Action to caFree;.
procedure TMyForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
Stacey
-----Original Message-----
From: Paul Mckenzie [mailto:[EMAIL PROTECTED]
Sent: Thursday, 18 March 2004 16:23
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Self Freeing
But I want to self Free - ie immediately after executing its event it frees
itself (eg OnClick).
Regards
Paul McKenzie
Analyst Programmer
SMSS Ltd.
----- Original Message -----
From: Stacey Verner <mailto:[EMAIL PROTECTED]>
To: NZ Borland Developers Group - <mailto:[EMAIL PROTECTED]> Delphi List
Sent: Thursday, March 18, 2004 4:07 PM
Subject: RE: [DUG] Self Freeing
Explicitly free it when you are done with it (maby add it to a list?) or set
its owner to something valid so when the owner component is freed the
dynamically created component will also be freed.
Stacey
-----Original Message-----
From: Paul Mckenzie [mailto:[EMAIL PROTECTED]
Sent: Thursday, 18 March 2004 15:55
To: Delphi List - Delphi
Subject: [DUG] Self Freeing
What is the best way for a dynamically created component to free itself ?
Regards
Paul McKenzie
Analyst Programmer
SMSS Ltd.
_____
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This communication contains information that is confidential and the
copyright of ensynergy Limited or a third party.
If you are not the intended recipient of this communication please delete
and destroy all copies and telephone ensynergy Limited on +64 9 3551591
immediately. If you are the intended recipient of this communication you
should not copy, disclose or distribute this communication without the
authority of ensynergy Limited.
Any views expressed in this communication are those of the individual
sender, except where the sender specifically states them to be the views of
ensynergy Limited.
Except as required by law, ensynergy Limited does not represent, warrant
and/or guarantee that the integrity of this communication has been
maintained nor that the communication is free of errors, virus, interception
or interference.
_____
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi
Disclaimer : This communication contains information that is confidential
and the copyright of ensynergy Limited or a third party. If you are not the
intended recipient of this communication please delete and destroy all
copies and telephone ensynergy Limited on +64 9 3551591 immediately. If you
are the intended recipient of this communication you should not copy,
disclose or distribute this communication without the authority of ensynergy
Limited. Any views expressed in this communication are those of the
individual sender, except where the sender specifically states them to be
the views of ensynergy Limited. Except as required by law, ensynergy Limited
does not represent, warrant and/or guarantee that the integrity of this
communication has been maintained nor that the communication is free of
errors, virus, interception or interference.
----------------------------------------------------------------------------
----
> _______________________________________________
> Delphi mailing list
> [EMAIL PROTECTED]
> http://ns3.123.co.nz/mailman/listinfo/delphi
>
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi