We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

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

Tom Knowlton
Tom Knowlton asked
on
Medium Priority
168 Views
Last Modified: 2010-04-04
If some buttons are created on a Form at runtime....how do you get rid of them?
Comment
Watch Question

Tom KnowltonWeb developer

Author

Commented:
Edited text of question
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Commented:
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.
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
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
Tom KnowltonWeb developer

Author

Commented:
viktornet:

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

Tom
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.