Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

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

AW: FileStream mit "TIniFile Funktionalität".Methoden

  Alt 26. Mai 2014, 15:17
Bis auf die Tatsache, dass du dich jetzt mit einem TMemIniFile verheiratet hast sieht das doch gut aus.

Wenn du eine Klasse geschrieben hättest, die etwas näher bei deiner Anwendung und etwas weiter weg von TMemIniFile ist, dann wäre das flexibler.

Delphi-Quellcode:
type
  TFoo = class( TCustomIniFile )
  private
    FIniFile : TCustomIniFile;
  public
    constructor Create( AIniFile : TCustomIniFile );

    // Alle Methoden auf die interne FIniFile umleiten

    procedure WriteMetaFile( const Section, Name : string; const Value : TMetaFile );
    procedure ReadMetaFile( const Section, Name : string; const Value : TMetaFile );
  end;

constructor TFoo.Create( AIniFile : TCustomIniFile );
begin
  inherited Create;
  if not Assigned( AIniFile )
  then
    raise EArgumentNilException.Create( 'TFoo: AIniFile' );
  FIniFile := AIniFile;
end;

procedure TFoo.WriteMetaFile( const Section, Name : string; const Value : TMetaFile );
var
  LStream : TStream;
begin
  LStream := TMemoryStream.Create;
  try
    Value.WriteToStream( LStream );
    LStream.Position := 0;
    FIniFile.WriteBinaryStream( Section, Name, LStream );
  finally
    LStream.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 (26. Mai 2014 um 15:23 Uhr)
  Mit Zitat antworten Zitat