Okay ... ich hab das glaube ich immernoch nicht so ganz verstanden.
(Ihr müsst das entschuldigen, ich arbeite das erste Mal mit FileStreams und mein Programmierlehrer kann das nur in C#, nicht in Delphi x.x)
Habe die Save/Load mal wie folgt angepasst, aber irgendwie steht in den Variablen Name und Info beim Laden nurnoch müll ...
Delphi-Quellcode:
// Load a existing List from a specific Filepath
procedure TListHandler.Load(const FilePath: String);
var
F_Stream: TFileStream;
lngth: Integer;
strlngth: Integer;
I: Integer;
name, Info: String;
begin
try
F_Stream := TFileStream.Create(FilePath, fmOpenRead);
F_Stream.ReadBuffer(lngth, SizeOf(lngth));
List.Length := lngth;
for I := 0 to List.Length - 1 do
begin
F_Stream.ReadBuffer(strlngth, SizeOf(strlngth));
SetLength(Name, strlngth);
F_Stream.ReadBuffer(Name[1], strlngth*SizeOf(Name[1]));
List.Item[i].Name := Name;
F_Stream.ReadBuffer(lngth, SizeOf(lngth));
SetLength(Info, lngth);
F_Stream.ReadBuffer(Info[1], strlngth*SizeOf(Info[1]));
List.Item[i].Info := Info;
F_Stream.ReadBuffer(lngth, SizeOf(lngth));
List.Item[i].ID := lngth;
end;// for
finally
F_Stream.Free;
end; // finally
end; // Load
// #############################################################################
// Save the whole List as it is to a pre-specified Filepath
procedure TListHandler.Save(const FilePath: String);
var
F_Stream: TFileStream;
lngth: Integer;
strLngth: Integer;
I: Integer;
begin
try
F_Stream := TFileStream.Create(FilePath, fmCreate);
lngth := List.Length;
F_Stream.WriteBuffer(lngth, SizeOf(lngth));
for I := 0 to List.Length - 1 do
begin
strlngth := Length(List.Item[I].Name);
F_Stream.WriteBuffer(strlngth, SizeOf(strlngth));
F_Stream.WriteBuffer(List.Item[I].Name[1],
strlngth*SizeOf(List.Item[I].Name[1]));
strlngth := Length(List.Item[i].Info);
F_Stream.WriteBuffer(strlngth, SizeOf(strlngth));
F_Stream.WriteBuffer(List.Item[I].Info[1],
strlngth*SizeOf(List.Item[I].Info[1]));
lngth := List.Item[i].ID;
F_Stream.WriteBuffer(strlngth, SizeOf(strlngth));
end; // for
finally
F_Stream.Free;
end;
end; // Save