Registriert seit: 18. Aug 2004
Ort: Brackenheim VS08 Pro
2.876 Beiträge
|
Re: TStream in (dp)CollectionItem speichern
17. Aug 2006, 11:21
Nicht wirklich getestet .
Delphi-Quellcode:
TSerializableMemoryStream = class(TInterfacedPersistent, IStreamPersist)
private
fStream: TMemoryStream;
procedure LoadFromStream(aStream: TStream);
procedure SaveToStream(aStream: TStream);
function GetStream: TMemoryStream;
protected
procedure DefineProperties(Filer: TFiler); override;
public
destructor Destroy;
property InnerStream: TMemoryStream read GetStream;
end;
[...]
{ TSerializableMemoryStream }
procedure TSerializableMemoryStream.DefineProperties(Filer: TFiler);
begin
Filer.DefineBinaryProperty('InnerStream', LoadFromStream, SaveToStream, true);
end;
destructor TSerializableMemoryStream.Destroy;
begin
fStream.Free;
end;
function TSerializableMemoryStream.GetStream: TMemoryStream;
begin
if (fStream = nil) then
fStream := TMemoryStream.Create();
Result := fStream;
end;
procedure TSerializableMemoryStream.LoadFromStream(aStream: TStream);
begin
InnerStream.LoadFromStream(aStream);
end;
procedure TSerializableMemoryStream.SaveToStream(aStream: TStream);
begin
InnerStream.SaveToStream(aStream);
end;
Sebastian Moderator in der EE
|