Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting rid of buttons I've created dynamically at run-time

Posted on 1998-08-08
6
Medium Priority
?
142 Views
Last Modified: 2010-04-04
If some buttons are created on a Form at runtime....how do you get rid of them?
0
Comment
Question by:Tom Knowlton
[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
  • 3
  • 2
6 Comments
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 1361745
Edited text of question
0
 
LVL 10

Accepted Solution

by:
viktornet earned 120 total points
ID: 1361746
Use NameOfCreatedButton.Free;
or like this.....

var i : integer;
begin
  for i := 0 to ComponentCount - 1 do
    begin
      if Components[i] is TButton then
         TButton(Components[i]).Free;  
    end;
end;
-------
Hope this helps.....

Regards,
Viktor Ivanov
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361747
Viktornet's example is correct, you can also : when you create them, put them in a list. And then iterate through this list to destroy them.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Expert Comment

by:viktornet
ID: 1361748
this is with TStringList......

if List is global variable, and you create it in formOnCreate, and destroy it in formOnDestroy, then when you want to free the buttons just enter this.,.....
When you create button use this....
List.Items.Add(ButtonName.Name);
to destroy all buttons use this///...

var i : integer;
for i := 0 to List.Items.Count - 1 do
  begin
    TButton(FindComponent('Button' + IntToStr(i+1))).Free;
  end;
//Check it out, since I've written it here, don't have Delphi open right now....

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1361749
A little fix over here....

     var i : integer;
     for i := 0 to List.Items.Count - 1 do
       begin
         TButton(List.Items[i]).Free;
       end;
Check this out too...

//Vik
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 1361750
viktornet:

That solution you gave me worked like magic.  I'll throw in another 10 points for your trouble.

Tom
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 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