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

  • Home
  • SEARCH
  • 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 7421107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:21:08+00:00 2026-05-29T08:21:08+00:00

I am using C++ Builder to create a VCL form application. Right now I

  • 0

I am using C++ Builder to create a VCL form application. Right now I have a TFrame containing a bunch of components and it looks like this…

enter image description here

I also have a button call “Add”. Basically every time I press that Add button on the form, a new TFrame is added to it and below the previous one making something that looks like a table. And in order to add duplicates I have to rename the TFrame each time before it is created.

    int __fastcall TForm1::AddMapCells(void)
    {
        Num++;
        TFrame1 * MyFrame = new TFrame1(Form1);
        MyFrame->Parent=Form1;
        MyFrame->Name = "TFrame" + IntToStr(Num);
        MyFrame->Top = 23*Num;
        return Num;
    }

So then the naming of TFrame would be TFrame1, TFrame2, TFrame3, etc.

The problem now is I want to make it so then each time I press the ‘X’ button of a TFrame, it deletes that TFrame and I’m not quite sure how to do it. I was thinking maybe each time I create a TFrame I can also rename the ‘X’ button so then it’s like Button1, Button2, Button3, etc. And then to delete the program would just match ButtonX with TFrameX to identify which TFrame to delete. For example, if I press Button 4, it should match up with TFrame4 and delete TFrame4.

I don’t know how to implement this idea. Or would there be an easier way of doing this?

  • 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-05-29T08:21:09+00:00Added an answer on May 29, 2026 at 8:21 am

    A simple solution would be to let the TFrame instances free themselves for you. Assign an OnClick event handler to the X button and have it post a queued message to its parent TFrame window via PostMessage(), then give the TFrame class a message handler that frees the TFrame instance when that message is processed (this is how the TForm::Release() method works), eg:

    void __fastcall TFrame1::CloseButtonClick(TObject *Sender)
    {
        // CM_RELEASE is defined in Controls.hpp
        PostMessage(Handle, CM_RELEASE, 0, 0);
    } 
    
    void __fastcall TFrame1::WndProc(TMessage &Message)
    {
        if (Message.Msg == CM_RELEASE)
        {
            delete this;
            return;
        }
    
        TFrame::WndProc(Message);
    }
    

    If you need your parent TForm to be notified of the TFrame being closed (for instance, to reposition lower TFrame instances), you can expose a custom TNotifyEvent event in the TFrame class and have your TForm assign an event handler to it, eg:

    class TFrame1 : public TFrame
    {
    private:
        TNotifyEvent FOnClose;
        ...
    public:
        ...
        __property TNotifyEvent OnClose = {read=FOnClose, write=FOnClose};
    };
    
    void __fastcall TFrame1::CloseButtonClick(TObject *Sender)
    {
        if (FOnClose != NULL) FOnClose(this);
        PostMessage(Handle, CM_RELEASE, 0, 0);
    } 
    
    void __fastcall TFrame1::WndProc(TMessage &Message)
    {
        if (Message.Msg == CM_RELEASE)
        {
            delete this;
            return;
        }
    
        TFrame::WndProc(Message);
    }
    

    .

    int __fastcall TForm1::AddMapCells(void) 
    { 
        Num++; 
        TFrame1 * MyFrame = new TFrame1(this); 
        MyFrame->Parent = this; 
        MyFrame->Name = "TFrame" + IntToStr(Num); 
        MyFrame->Top = 23*Num; 
        MyFrame->OnClose = &FrameClosed;
        return Num; 
    } 
    
    void __fastcall TForm1::FrameClosed(TObject *Sender)
    {
        // Sender is the TFrame1 instance whose X button was clicked.
        // It will auto-free itself after this method exits...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Flash Builder 4 to create an application. I need to set an
I'm using Flex Builder more and more and attempting to create a fairly asset
I'm using C# WinForms to create a level builder for my XNA game. I
I created a label using Interface Builder, and now I want to set the
I am using Borland Builder C++. I have a memory leak and I know
I'm using Flex Builder 3 now and it suddenly refuses to start debugging session.
I am using Qt Builder to create a simple window. I used the menu
what's the difference in using tag builder and string builder to create a table
I am using Flash Builder 4.6 Yesterday the project is working fine. Now it
Using Flash Builder 4 (with 4.1 flex). Trying to create a state change after

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.