Registriert seit: 18. Aug 2004
Ort: Edewecht
712 Beiträge
Delphi 5 Professional
|
Re: TFileStream Problem
10. Jul 2005, 13:13
Zitat von kurtm1:
Ich möchte eine String Variable ganz normal abspeichern (mittels TFilestream)
Mit TFileStream:
Delphi-Quellcode:
procedure WriteStringToFile(const FileName, S: String);
begin
try
with TFileStream.Create(FileName, fmCreate) do
try
if Length(S) > 0 then
WriteBuffer(S[1], Length(S));
finally
Free;
end;
except
end;
end;
procedure ReadStringFromFile(const FileName: String; var S: String);
begin
SetLength(S, 0);
try
with TFileStream.Create(FileName, fmOpenRead) do
try
if Size > 0 then
begin
SetLength(S, Size);
ReadBuffer(S[1], Size);
end;
finally
Free;
end;
except
end;
end;
Ich würde es aber ohne TFileStream machen:
Delphi-Quellcode:
procedure WriteStringToFile( const FileName, S: String);
var
Handle: Integer;
begin
Handle := FileCreate(FileName);
if Handle <> -1 then
begin
if Length(S) > 0 then
FileWrite( Handle, S[1], Length(S));
FileClose( Handle);
end;
end;
procedure ReadStringFromFile( const FileName: String; var S: String);
var
Handle: Integer;
Size: Integer;
begin
SetLength(S, 0);
Handle := FileOpen(FileName, fmOpenRead);
if Handle <> -1 then
begin
Size := FileSeek( Handle, 0, soFromEnd);
if Size > 0 then
begin
SetLength(S, Size);
FileSeek( Handle, 0, soFromBeginning);
FileRead( Handle, S[1], Size);
end;
FileClose( Handle);
end;
end;
Ciao, Sprint.
"I don't know what I am doing, but I am sure I am having fun!"
|
|
Zitat
|