
Untitled
By: a guest on
May 1st, 2012 | syntax:
None | size: 1.52 KB | hits: 17 | expires: Never
Deleting TFrame from form at run time
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;
}
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);
}
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...
}