Solved

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

Posted on 1998-08-08
6
137 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Newbie Thread Programming 1 161
creating threads in delphi 1 136
SUM 2 INTEGER ARRAYS INTO 1 10 108
Graphics32 under Delphi 10.1 Berlin 2 105
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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