Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9194459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:25:07+00:00 2026-06-17T21:25:07+00:00

I have a trouble. I create a label object. var lbl:Tlabel; begin lbl:=TLabel.Create(nil); ….

  • 0

I have a trouble.
I create a label object.

var lbl:Tlabel;
begin
lbl:=TLabel.Create(nil);
....

Ok, but after destroying it, it still remains on form.
There is my code:

lbl.free;
lbl := nil;

After executing it, controls stays on form.
There is a solution? I need to destroy this component, this should dissapear from form.
Thanks.

EDIT : RemoveControl(AControl: TControl); procedure isnt working.
EDIT2:

for I := 0 to 4 do begin
 lbl:=TLabel.Create(nil);
lbl.Top :=  100+z*i;
 lbl.Left := 88;
 Lbl.Width := 80;
  Lbl.Height := 14;
  lbl.Font.Size := 9;
 lbl.Caption := nm[i];
 Form1.InsertControl(lbl);

This control stays on form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:25:09+00:00Added an answer on June 17, 2026 at 9:25 pm

    Destroying a control is no different from destroying any other object. Simply call Free on the object and you are done.

    The only time that you run into problems is when you call Free on an object for whom an event handler is running. For example freeing a button in that button’s OnClick handler. In such a scenario you need to post a message to your form, and then free the button when that queued message is processed.

    Your problem is that you are calling Free on the wrong object. You created 5 labels but only held on to a reference to one of them. You need to free all 5 labels. You’ll want an array or a list to hold the label references. Then you’ll be able to free them all.

    In your form declare an array:

    FLabels: array of TLabel;
    

    When you create them:

    SetLength(FLabels, 5);
    for i := 0 to high(FLabels) do
    begin
      FLabels[i] := TLabel.Create(Self);
      .......
    end;
    

    Destroy like this:

    for i := 0 to high(FLabels) do
      FLabels[i].Free;
    FLabels := nil;
    

    Some general advice for you. When you are faced with a problem, simplify it. Why try to debug object destruction with multiple controls? Create a blank app, and add a single control. Then try to delete that single control. Then move to multiple controls. Don’t troubleshoot the complex version, always try to simplify.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble launching Glassfish v3 on Mac In Windows, after installation of Glassfish
I need to create an algorithm to layout some hierarchical data but have never
I'm a newbie in blackberry. I have a trouble when create a program to
I'm a jQuery newbie, and I have trouble with a little script I created.
I'm having trouble obtaining data with a macro I've created using XSLT. I have
I have trouble figuring out why a simple division like this one always returns
We have trouble implementing a nice session mechanism in JSP. One of our requirement
I have trouble with strange behavior of for..in cycle in JavaScript. I have the
I have trouble doing this... You may want to get the same result as
I have trouble shooting at file download problem. In Chrome, the download works fine.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.