unit Unit2;
interface
uses
MyComponent,
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
type
TForm2 =
class( TForm )
Button1: TButton;
Button2: TButton;
procedure FormCreate( Sender: TObject );
procedure Button1Click( Sender: TObject );
procedure Button2Click( Sender: TObject );
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
FMyComponent: TMyComponent;
procedure CreateMyComponent;
procedure MyComponentDestroy( Sender: TObject );
public
{ Public-Deklarationen }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click( Sender: TObject );
begin
FreeAndNil( FMyComponent );
end;
procedure TForm2.Button2Click( Sender: TObject );
begin
CreateMyComponent( );
end;
procedure TForm2.CreateMyComponent;
begin
FreeAndNil( FMyComponent );
FMyComponent := TMyComponent.Create( Self );
FMyComponent.OnDestroy := MyComponentDestroy;
end;
procedure TForm2.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TForm2.FormCreate( Sender: TObject );
begin
CreateMyComponent( );
end;
procedure TForm2.MyComponentDestroy( Sender: TObject );
begin
if not( csDestroying
in Application.ComponentState )
then
ShowMessage( '
Ich bin dann mal weg!' );
end;
end.