Registriert seit: 6. Apr 2005
10.109 Beiträge
|
Re: Zeilenweise in Datei Schreiben
2. Nov 2005, 07:28
Hallo Evian,
hier hast du ein wenig Code, der dir das Prinzip zeigt:
Delphi-Quellcode:
procedure PrependLines(s: TStrings; fileName: string);
var
fs: TFileStream;
fn: string;
begin
SetLength(fn, MAX_PATH);
if GetTempFileName(' .', ' TMP', 0, @fn[1]) = 0
then raise Exception.Create(SysErrorMessage(GetLastError))
else SetLength(fn, Pred(Pos(#0, fn)));
fs := TFileStream.Create(fileName, fmOpenRead, fmShareDenyWrite);
with TFileStream.Create(fn, fmCreate) do
begin
Write(s.GetText^, StrLen(s.GetText));
CopyFrom(fs, fs.Size);
Free;
end;
fs.Free;
DeleteFile(fileName);
RenameFile(fn, fileName);
end;
procedure TDemoForm.ButtonClick(Sender: TObject);
const
fn = ' c:\daten\temp.txt';
begin
with Memo.Lines do
begin
Clear;
Add(' 123');
Add(' abc');
end;
PrependLines(Memo.Lines, fn);
end;
Grüße vom marabu
|
|
Zitat
|