Solved

Destruction of visual controls at runtime

Posted on 1999-01-25
2
159 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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…
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.
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…

830 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