Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 1.52 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Deleting TFrame from form at run time
  2. int __fastcall TForm1::AddMapCells(void)
  3.     {
  4.         Num++;
  5.         TFrame1 * MyFrame = new TFrame1(Form1);
  6.         MyFrame->Parent=Form1;
  7.         MyFrame->Name = "TFrame" + IntToStr(Num);
  8.         MyFrame->Top = 23*Num;
  9.         return Num;
  10.     }
  11.        
  12. void __fastcall TFrame1::CloseButtonClick(TObject *Sender)
  13. {
  14.     // CM_RELEASE is defined in Controls.hpp
  15.     PostMessage(Handle, CM_RELEASE, 0, 0);
  16. }
  17.  
  18. void __fastcall TFrame1::WndProc(TMessage &Message)
  19. {
  20.     if (Message.Msg == CM_RELEASE)
  21.     {
  22.         delete this;
  23.         return;
  24.     }
  25.  
  26.     TFrame::WndProc(Message);
  27. }
  28.        
  29. class TFrame1 : public TFrame
  30. {
  31. private:
  32.     TNotifyEvent FOnClose;
  33.     ...
  34. public:
  35.     ...
  36.     __property TNotifyEvent OnClose = {read=FOnClose, write=FOnClose};
  37. };
  38.  
  39. void __fastcall TFrame1::CloseButtonClick(TObject *Sender)
  40. {
  41.     if (FOnClose != NULL) FOnClose(this);
  42.     PostMessage(Handle, CM_RELEASE, 0, 0);
  43. }
  44.  
  45. void __fastcall TFrame1::WndProc(TMessage &Message)
  46. {
  47.     if (Message.Msg == CM_RELEASE)
  48.     {
  49.         delete this;
  50.         return;
  51.     }
  52.  
  53.     TFrame::WndProc(Message);
  54. }
  55.        
  56. int __fastcall TForm1::AddMapCells(void)
  57. {
  58.     Num++;
  59.     TFrame1 * MyFrame = new TFrame1(this);
  60.     MyFrame->Parent = this;
  61.     MyFrame->Name = "TFrame" + IntToStr(Num);
  62.     MyFrame->Top = 23*Num;
  63.     MyFrame->OnClose = &FrameClosed;
  64.     return Num;
  65. }
  66.  
  67. void __fastcall TForm1::FrameClosed(TObject *Sender)
  68. {
  69.     // Sender is the TFrame1 instance whose X button was clicked.
  70.     // It will auto-free itself after this method exits...
  71. }