?
Solved

can an object 2 destroy itself?

Posted on 2003-02-20
7
Medium Priority
?
313 Views
Last Modified: 2010-04-04
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
Comment
Question by:pililowski
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7988229
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
 
LVL 3

Accepted Solution

by:
sfock earned 200 total points
ID: 7988691
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
 

Expert Comment

by:NightAwk
ID: 7988813
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7991199
also check out the Release proc.
0
 

Expert Comment

by:CleanupPing
ID: 9317156
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
 
LVL 10

Expert Comment

by:kacor
ID: 9928818
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question