Solved

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

Posted on 1998-08-08
6
139 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 30 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
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!

 
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

Technology Partners: 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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

696 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