Solved

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

Posted on 1998-08-08
6
136 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:knowlton
  • 3
  • 2
6 Comments
 
LVL 5

Author Comment

by: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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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