unit TestUnit;
interface
uses Classes, SysUtils, Contnrs;
type TObjekt1 =
class(TObject)
private
FID : Integer;
FValue : Integer;
public
property ID : Integer
read FID
write FID;
property Value : Integer
read FValue
write FValue;
procedure SavetoStream(AStream : TStream);
procedure LoadFromStream(AStream : TStream);
constructor Create(AID : Integer; AValue : Integer);
end;
type TObjektListe =
class(TObjectList)
public
procedure LoadFromStream(AStream : TStream);
procedure SaveToStream(AStream : TStream);
end;
implementation
{ TObjekt1 }
constructor TObjekt1.Create(AID, AValue: Integer);
begin
FID := AID;
FValue := AValue;
end;
procedure TObjekt1.LoadFromStream(AStream: TStream);
begin
AStream.ReadBuffer(FID, SizeOf(FID));
AStream.ReadBuffer(FValue, SizeOf(FValue));
end;
procedure TObjekt1.SavetoStream(AStream: TStream);
begin
AStream.WriteBuffer(FID, SizeOf(FID));
AStream.WriteBuffer(FValue, SizeOf(FValue));
end;
{ TObjektListe }
procedure TObjektListe.LoadFromStream(AStream: TStream);
var FCount : Integer;
i: Integer;
begin
(* Liste löschen *)
Clear;
(* Anzahl der Elemente auslesen *)
AStream.ReadBuffer(FCount, SizeOf(Fcount));
for i := 0
to FCount-1
do begin
Add(TObjekt1.Create(-1, -1));
TObjekt1(Last).LoadFromStream(AStream);
end;
end;
procedure TObjektListe.SaveToStream(AStream: TStream);
var FCount : Integer;
i: Integer;
begin
(* Anzahl der Elemente speichern *)
FCount := Count;
AStream.WriteBuffer(FCount, SizeOf(FCount));
(* Einzelne Elemente speichern *)
for i := 0
to FCount-1
do
TObjekt1(Items[i]).SavetoStream(AStream);
end;
end.