Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#15

AW: optionale Parameter mit object-type?

  Alt 19. Mai 2016, 18:47
Mach es doch gleich richtig
Delphi-Quellcode:
type
  TScript = class
  private
   FLine: word;
   FState: TStatus;
   FLines:TStringList;
   FError:string;
  public
    property Error: string read FError;
    property Lines: TStringList read FLines;
  public
   constructor Create( aScriptFile : string );
   destructor Destroy; override;
  end;

constructor TScript.Create( aScriptFile : string );
begin
  inherited Create;
  FLines := TStringList.Create;
  FLines.LoadFromFile( aScriptFile );
end;

destructor TScript.Destroy;
begin
  FLines.Free;
  inherited;
end;
Kaum ein Unterschied zu object nur dass wir jetzt die Instanz erzeugen (statt Init ) und wieder freigeben (wenn nicht mehr benötigt). Bei der Freigabe räumen wir aber auch den Speicher kontrolliert auf:
Delphi-Quellcode:
procedure Foo;
var
  lScript: TScript;
  lStatus: TStatus;
begin
  lScript := TScript.Create( 'whatever.script' );
  try
    LStatus := Interpreter( '42', TModus.Whatever, lScript );
  finally
    lScript.Free;
  end;
end;
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)

Geändert von Sir Rufo (19. Mai 2016 um 18:49 Uhr)
  Mit Zitat antworten Zitat