Speichern:
Delphi-Quellcode:
var
FileStream: TMemoryStream;
begin
FileStream := TMemoryStream.Create;
FileStream.Write(Length(Memo1.Text), SizeOf(Integer));
FileStream.Write(Memo1.Text, Length(Memo1.Text));
FileStream.Write(Length(Memo2.Text), SizeOf(Integer));
FileStream.Write(Memo2.Text, Length(Memo1.Text));
{...}
FileStream.SaveToFile('FileName');
FileStream.Free;
end;
Laden:
Delphi-Quellcode:
var
FileStream: TMemoryStream;
pos,l,i: Integer;
begin
FileStream := TMemoryStream.Create;
FileStream.LoadFromFile('FileName');
pos := 0;
l := 0;
for i := 1 to 5 do
begin
FileStream.Position := pos;
FileStream.Read(l, SizeOf(Integer));
FileStream.Position := pos + SizeOf(Integer);
case i of
1: FileStream.Read(Memo1.Text ,l);
{...}
5: FileStream.Read(Memo5.Text ,l);
end;
pos := pos + l + SizeOf(Integer);
end;
FileStream.Free;
end;
Ist ungetestet, aber müsste so klappen.
Zur Struktur: Du speicherst immer zuerst die Anzahl der Zeichen und dann den Text selber. Beim Auslesen ebenso.