Achso. Genial. Wenn ich CopyFrom richtig in der Hilfe gelesen habe, dann wird dann sogar die aktuelle Position im FileStream um Count angegebene Anzahl Bytes verschoben oder betrifft das die Source (den Temp. MemoryStream)?
Delphi-Quellcode:
function TFileStreamExt.ReadInt64: int64;
begin
ReadBuffer(Result, SizeOf(int64));
end;
procedure TFileStreamExt.ReadMetaFile(MetaFile: TMetaFile);
var
MemoryStream: TMemoryStream;
MemoryStreamSize: int64;
begin
MemoryStream := TMemoryStream.Create;
try
MemoryStreamSize := ReadInt64;
MemoryStream.CopyFrom(Self, MemoryStreamSize);
MetaFile.LoadFromStream(MemoryStream);
finally
MemoryStream.Free;
end;
end;
procedure TFileStreamExt.WriteInt64(const Value: int64);
begin
WriteBuffer(Value, SizeOf(int64));
end;
procedure TFileStreamExt.WriteMetaFile(MetaFile: TMetaFile);
var
MemoryStream: TMemoryStream;
begin
MemoryStream := TMemoryStream.Create;
try
MetaFile.SaveToStream(MemoryStream);
WriteInt64(MemoryStream.Size);
Self.CopyFrom(MemoryStream, MemoryStream.Size);
finally
MemoryStream.Free;
end;
end;