Einzelnen Beitrag anzeigen

Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.464 Beiträge
 
Delphi 12 Athens
 
#18

AW: Verständnisfrage zu Unit: Initialization und Finalization

  Alt 5. Okt 2016, 11:41
Ich verwende Initialization und Finalization, da es im Delphi2007 Class-Constructor und Class-Destructor noch nicht gibt.

Beispiel:
Delphi-Quellcode:
unit MyFactory;

interface

uses
  Contnrs;

type
  TMyObject = class abstract(TObject)
  end;

  TMyClass = class of TMyObject;

  TMyFactory = class(TObject)
  private
    class var
      FClassList: TClassList;
  protected
    class procedure Initialize;
    class procedure Finalize;
  public
    class procedure RegisterClass(AClass: TMyClass);
    class procedure UnRegisterClass(AClass: TMyClass);
  end;

implementation

class procedure TMyFactory.Initialize;
begin
  FClassList := TClassList.Create;
end;

class procedure TMyFactory.Finalize;
begin
  FClassList.Free;
end;

class procedure TMyFactory.RegisterClass(AClass: TMyClass);
begin
  FClassList.Add(AClass);
end;

class procedure TMyFactory.UnRegisterClass(AClass: TMyClass);
begin
  FClassList.Remove(AClass);
end;

initialization
  TMyFactory.Initialize;

finalization
  TMyFactory.Finalize;

end.
  Mit Zitat antworten Zitat