Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Destruction of visual controls at runtime

Posted on 1999-01-25
2
Medium Priority
?
165 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 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Screencast - Getting to Know the Pipeline

916 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