Kleine Starthilfe, ohne Gewähr.
Delphi-Quellcode:
const
MyObjectFile = 'myobject.dat';
type
TMyObject = class(TObject)
FDynArray: array of integer;
constructor Create(len: integer);
destructor Destroy; override;
procedure Load; virtual;
procedure Save; virtual;
end;
constructor TMyObject.Create(len: integer);
var
i: integer;
begin
inherited Create;
SetLength(FDynArray, len);
for i := 0 to len - 1 do
FDynArray[i] := Random(100);
end;
destructor TMyObject.Destroy;
begin
FDynArray := nil;
inherited;
end;
procedure TMyObject.Load;
var
s: TFileStream;
i: integer;
begin
s := TFileStream.Create(MyObjectFile, fmOpenRead, fmShareDenyWrite);
for i := Low(FDynArray) to High(FDynArray) do
s.Read(FDynArray[i], SizeOf(integer));
s.Free;
end;
procedure TMyObject.Save;
var
s: TFileStream;
i: integer;
begin
s := TFileStream.Create(MyObjectFile, fmCreate, fmShareDenyWrite);
for i := Low(FDynArray) to High(FDynArray) do
s.Write(FDynArray[i], SizeOf(integer));
s.Free;
end;