Solved

Destruction of visual controls at runtime

Posted on 1999-01-25
2
151 Views
Last Modified: 2010-04-06
Hi,

I have a list of buttons defined in a TComponentList. I can place these buttons on a form by setting the parent property

(ComponentList.Items[i] as TButton).Parent := Form1;

This works fine and the buttons display on the form, however I now wish to change the contents of ComponentList and re-draw the buttons on the form.

My question is how do I get rid of the buttons already on the form?

I have tried

(ComponentList.Items[i] as TButton).Free;

This certainly messes up the buttons but they are still on the form.

I have tried

(ComponentList.Items[i] as TButton).Parent := nil;

Does nothing!, well I sure it does but I know not what.

Regards

Chris
0
Comment
Question by:ChrisBerry
2 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 50 total points
ID: 1363205
Try TForm.RemoveControl instead of (ComponentList.Items[i] as TButton).Parent := nil
Then you may use TButton.Free if you want to destroy the button component.
0
 

Author Comment

by:ChrisBerry
ID: 1363206
Hi,

Thanks for your answer. I in fact had another problem where I was overlaying two sets of buttons and not knowing so.

(ComponentList.Items[i] as TButton).Free;

and

(ComponentList.Items[i] as TButton).Parent := nil;

both work fine, I just did not know it because a set of buttons remained.

Thanks

Chris


0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now