program MyLazTest;
{$mode Delphi}{$M+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils, CustApp
{ you can add units after this };
type
{ My B }
B = class( TObject)
public
constructor Create(Sender : TObject);
destructor Destroy; override;
end;
{ My A }
A = class( TObject)
myB_in_A : B;
public
constructor Create(Sender : TObject);
destructor Destroy; override;
end;
{ MyApplication_1 }
MyApplication_1 = class(TCustomApplication)
myA : A;
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure WriteHelp; virtual;
end;
constructor A.Create(Sender : TObject);
begin
inherited Create();
WriteLn('Object of Class A generated.');
myB_in_A := B.Create(Self);
end;
destructor A.Destroy;
begin
//myB_in_A.Destroy;
WriteLn('Object of Class A released.');
inherited Destroy;
end;
constructor B.Create(Sender : TObject);
begin
inherited Create();
WriteLn('Object of Class B generated.');
end;
destructor B.Destroy;
begin
WriteLn('Object of Class B released.');
inherited Destroy;
end;
{ MyApplication_1 }
procedure MyApplication_1.DoRun;
var
ErrorMsg: String;
begin
// quick check parameters
ErrorMsg:=CheckOptions('h', 'help');
if ErrorMsg<>'' then begin
ShowException(Exception.Create(ErrorMsg));
Terminate;
Exit;
end;
// parse parameters
if HasOption('h', 'help') then begin
WriteHelp;
Terminate;
Exit;
end;
myA := A.create(Self);
Sleep(1000);
WriteLn('Hallo...');
myA.free; // here I expect both destructors called
{ add your program here }
Sleep(2000);
// stop program loop
Terminate;
end;
constructor MyApplication_1.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
end;
destructor MyApplication_1.Destroy;
begin
inherited Destroy;
end;
procedure MyApplication_1.WriteHelp;
begin
{ add your help code here }
writeln('Usage: ', ExeName, ' -h');
end;
var
Application: MyApplication_1;
begin
Application:=MyApplication_1.Create(nil);
Application.Title:='My Application';
Application.Run;
Application.Free;
end.