procedure TForm1.FormCreate(Sender: TObject);
begin
savedialog1.filter := 'MeineDateiArt|*.new';
savedialog1.Options := savedialog1.Options + [ofOverwritePrompt];
savedialog1.DefaultExt := 'new';
opendialog1.filter := savedialog1.filter;
opendialog1.Options := opendialog1.Options + [ofPathMustExist, ofFileMustExist];
end;
procedure TForm1.speichern(Datei: string; arr: array of TRichedit);
var fs: TFilestream;
i, x: integer;
procedure speichere(re: TRichedit);
var ms: TMemorystream;
begin
ms := TMemorystream.Create;
re.lines.savetostream(ms);
i := ms.size;
ms.position := 0;
fs.writebuffer(i, sizeof(integer));
fs.copyfrom(ms, i);
ms.free;
end;
begin
fs := TFilestream.create(Datei, fmCreate or fmShareExclusive);
for x := 0 to high(arr) do speichere(arr[x]);
fs.free;
end;
procedure TForm1.laden(Datei: string; arr: array of TRichedit);
var fs: TFilestream;
i, x: integer;
function lade(re: TRichedit): boolean;
var ms: TMemorystream;
begin
ms := TMemorystream.Create;
try
fs.readbuffer(i, sizeof(integer));
ms.copyfrom(fs, i);
ms.position := 0;
re.lines.loadfromstream(ms);
result := true;
except
showmessage('FEHLER!'#13#10'Abbruch bei ' + re.name);
result := false;
end;
ms.free;
end;
begin
fs := TFilestream.create(Datei, fmOpenread);
for x := 0 to high(arr) do
if not lade(arr[x]) then break;
fs.free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if savedialog1.execute then
speichern(savedialog1.FileName, [Richedit1, Richedit2]);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if opendialog1.execute then
laden(opendialog1.FileName, [Richedit1, Richedit2, Richedit3]);
end;