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:
/* The following code allocates a TBitmap object that is used by the application when the main form is first created. The OnDestroy method frees the bitmap as the application shuts down. */ Graphics::TBitmap *LogoBmp; void __fastcall TForm1::FormCreate(TObject *Sender) { LogoBmp = new Graphics::TBitmap(); LogoBmp->LoadFromFile("../FACTORY.BMP"); } void __fastcall TForm1::FormDestroy(TObject *Sender) { delete LogoBmp; } void __fastcall TForm1::FormPaint(TObject *Sender) { Canvas->Brush->Bitmap = LogoBmp; Canvas->FillRect(Rect(0,0,100,100)); }
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) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|