RAD Studio VCL Reference
|
Occurs when the form is destroyed.
property OnDestroy: TNotifyEvent;
__property TNotifyEvent OnDestroy;
Use OnDestroy to perform special processing when the form is destroyed. Either implement this event or override the destructor of the class, but not both. This event should destroy any objects created in the OnCreate event.
C++ Examples:
/* This example uses the OnActiveControlChange event to detect when focus changes on the form. When focus changes, the hint for the active control is displayed on the status bar. To use this example, you must add a status bar to the form and set its SimplePanel property to true. Add a new public procedure, ActiveControlChanged, to the TForm1 class declaration. */ void _fastcall TForm1::ActiveControlChanged(System::TObject *Sender) { TWinControl *Active = NULL; for (int I = 0; I < Form1->ControlCount; I++) { TWinControl *Temp = dynamic_cast<TWinControl *>(Form1->Controls[I]); if (Temp && Temp->Focused()) Active = Temp; } if ((Active != NULL) && (Active->Hint != "")) StatusBar2->SimpleText = GetLongHint(Active->Hint) + " focus"; } void __fastcall TForm1::MouseOverChanged(TObject *Sender) { TWinControl *Active = dynamic_cast<TWinControl *>(Sender); if (Active != NULL) StatusBar1->SimpleText = GetLongHint(Active->Hint) + " mouse over"; } /* Assign this method as the OnActiveControlChange event handler by setting it from the form's OnCreate event handler: */ void __fastcall TForm1::FormCreate(TObject *Sender) { Screen->OnActiveControlChange = ActiveControlChanged; } /* Make sure you clean up the screen object when the form is freed by adding this OnDestroy event handler to the form: */ void __fastcall TForm1::FormDestroy(TObject *Sender) { Screen->OnActiveControlChange = 0; }
Delphi Examples:
{ The following code explicitly allocates memory for a pointer in the OnCreate event of Form1, then releases the memory in the OnDestroy event. Assume that MyPtr is a Pointer type field of TForm1. } procedure TForm1.FormCreate(Sender: TObject); begin New(MyPtr); end; procedure TForm1.FormDestroy(Sender: TObject); begin Dispose(MyPtr); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|