Mal schnell getestet und natürlich zuerst ein kleines Fehlerchen, mit blöder Auswirkung. (nur die lokalen Variablen wurden freigegeben)
Delphi-Quellcode:
type
TTest = class(TInterfacedObject, ITest)
Name: string;
constructor Create(Name: string);
destructor Destroy; override;
end;
Delphi-Quellcode:
type
ITest = interface
end;
TTest = class(TInterfacedObject, ITest)
Name: string;
constructor Create(Name: string);
destructor Destroy; override;
end;
class function TTest.Create(Name: string): ITest;
begin
Result := inherited Create;
(Result as TTest).Name := Name;
ShowMessage('Start ' + Name);
end;
destructor TTest.Destroy;
begin
ShowMessage('Stop ' + Name);
inherited;
end;
procedure TForm11.FormCreate(Sender: TObject);
var
Var1, Var2, Var3, Var4: ITest;
begin
Var1 := TTest.Create('Var1'); // Start Var1
var Inline1 := TTest.Create('Inline1'); // Start Inline1
TTest.Create('Temp1'); // Start Temp1
Beep;
if Tag = 0 then
Var2 := TTest.Create('Var2'); // Start Var2
if Tag = 0 then
var Inline2 := TTest.Create('Inline2'); // Start/Stop Inline2
if Tag = 0 then
TTest.Create('Temp2'); // Start/Stop Temp2
Beep;
if Tag = 0 then begin
Var3 := TTest.Create('Var3'); // Start Var3
var Inline3 := TTest.Create('Inline3'); // Start Inline3
TTest.Create('Temp3'); // Start Temp3
end; // Stop Temp3/Inline3
Beep;
if Tag = 0 then begin
Var4 := TTest.Create('Var4'); // Start Var4
var Inline4 := TTest.Create('Inline4'); // Start Inline4
TTest.Create('Temp4'); // Start Temp4
Beep;
begin
TTest.Create('Temp5'); // Start Temp5
end; // Stop Temp5
Beep;
begin
TTest.Create('Temp6'); // Start Temp6
Beep;
TTest.Create('Temp7'); // Start Temp7
Beep;
end; // Stop Temp7/Temp6
Beep;
begin
var Temp8 := TTest.Create('Temp8'); // Start Temp8
Beep;
Temp8 := TTest.Create('Temp9'); // Stop Temp8 / Start Temp9
Beep;
end; // Stop Temp9
Beep;
ShowMessage('Show'); // Show
Beep;
end; // Stop Temp4/Inline4
Beep;
end; // Stop Temp1/Inline1/Var4/Var3/Var2/Var1
Delphi-Quellcode:
class function TTest.Create(Name: string): ITest;
begin
ShowMessage('Start ' + Name);
Result := inherited Create;
(Result as TTest).Name := Name;
end;
begin
var Temp8 := TTest.Create('Temp8'); // Start Temp8
Beep;
Temp8 := TTest.Create('Temp9'); // Start Temp9 / Stop Temp8
Beep;
end; // Stop Temp9
Jo, egal ob mit Begin/End oder nicht ... IF reagiert
gleich einheitlich.