Link to home
Start Free TrialLog in
Avatar of pililowski
pililowski

asked on

can an object 2 destroy itself?

Hi there. It's me pililowski again.

I'm tryin' 2 do an object able 2 destroy itself at its OnClick event. When i free the object in this event an ugly crappy access violation happens.

"...
procedure TShadowBtn.Click(Sender: TObject);
begin
 Free;
 inherited Click;
end;
..."

My question is: Is it possible 2 do this with no errors? I mean if is it possible 2 make an object able to destroy itself by itself (with no help from other objects)?

If i find the way i'll make u know. Till then hope your answers. C ya!

 Mr. Pililowski
Avatar of kretzschmar
kretzschmar
Flag of Germany image

no,
but you can define a usermessage,
which you can send to self,
in the message-handler you
can free self as last statement.

see the release method of tform

meikl ;-)
ASKER CERTIFIED SOLUTION
Avatar of sfock
sfock

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NightAwk
NightAwk

well, first, the button is part of the object ??
so i am guessing u want to destroy a component.

my question : why destroy an object from one of it's member?

it would probably  be best to destroy the object from another button, who is not part of the object, or at least if thats not possible, just hide the object from the form, and it will be destoyed when the form closses.
also check out the Release proc.
pililowski:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to accept sfock's answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Some days and here is the Christmas Time. I wish good luck and good health for you all and for your loved ones

kacor
EE Cleanup Volunteer