• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

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
0
pililowski
Asked:
pililowski
1 Solution
 
kretzschmarCommented:
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 ;-)
0
 
sfockCommented:
well it is possible for an object to free itself, but it can't go on executing it's own code after destroying itself.

change your code to
procedure TShadowBtn.Click(Sender: TObject);
begin
inherited Click;
Free;
end;

or

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

and it will do what you want. even if i don't really understand why this shall make sense
0
 
NightAwkCommented:
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
DragonSlayerCommented:
also check out the Release proc.
0
 
CleanupPingCommented:
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.
0
 
kacorretiredCommented:
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
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now