Dann ist ja fast wie beim ersten mal ^_^
Habe Ratschlag angenommen und umgesetzt:
so in der IniHelper.pas
Delphi-Quellcode:
function ReadIniStream( const Filename, Section, Ident: String; const Value: TStream; const FolderOverride: String = '' ): Boolean;
var
FIniFile: TIniFile;
FName: String;
FMS: TMemoryStream;
begin
Result := False;
if ( Value <> nil ) then
begin
FMS := TMemoryStream.Create();
try
FName := GetIniFilename( Filename, FolderOverride );
if not SysUtils.FileExists( FName ) then
Exit;
FIniFile := TIniFile.Create( FName );
try
FIniFile.ReadBinaryStream( Section, Ident, FMS );
FMS.Position := 0;
Value.Position := 0;
Value.CopyFrom( FMS, FMS.Size );
finally
FIniFile.Free;
Value.Position := 0;
Result := True;
end;
finally
FMS.Free;
end;
end;
end;
und so in der demo
Delphi-Quellcode:
ms := TMemoryStream.Create();
try
S := 'Stream-Error';
if IniHelper.ReadIniStream( 'Testfile.cfg', 'Setup', 'StreamEntry', ms ) then
begin
S := IntToStr( ms.Size );
Memo1.Lines.Add( 'Stream-Size: ' + S );
S := '';
SetLength( S, ms.Size div 2 );
ms.Read( S[1], ms.Size );
Memo1.Lines.Add( 'Stream: ' + S );
ms.Free;
end
else
Memo1.Lines.Add( 'Stream-Error: ' + S );
except
Memo1.Lines.Add( 'Stream-Error: ' + S );
ms.Free;
end;