andrewyu
asked on
TFileStream
How can I write line from a String to a File through Delphi 6 ?
Can you give me section of sample code ?
Andrew
Can you give me section of sample code ?
Andrew
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or if You want streams:
procedure TForm1.Button1Click(Sender : TObject);
var F: TFileStream;
str: string;
lstr: Integer;
begin
str:='line of text';
lstr:=Length(str);
F:=TFileStream.Create('sam ple.txt',f mOpenWrite );
try
F.Read(str,lstr);
finally
F.Free;
end;
end;
ziolko.
procedure TForm1.Button1Click(Sender
var F: TFileStream;
str: string;
lstr: Integer;
begin
str:='line of text';
lstr:=Length(str);
F:=TFileStream.Create('sam
try
F.Read(str,lstr);
finally
F.Free;
end;
end;
ziolko.
ziolko,
wouldnt you need to change your last example :
from
F.Read(str,lstr);
To
F.Write(str,lstr);
??
wouldnt you need to change your last example :
from
F.Read(str,lstr);
To
F.Write(str,lstr);
??
smurff yeah my last example sucks, but it doesn't matter since Your is ok:-). just trying to make too many things at one time it always end with disaster:-)
ziolko.
ziolko.
ASKER
Smurff,
It is almost ok, but, how can I write them LINE by LINE ?
Andrew
It is almost ok, but, how can I write them LINE by LINE ?
Andrew
? use a tsringlist,
for its items (strings) tsringlist provides the methods
savetofile and
loadfromfile
meikl ;-)
for its items (strings) tsringlist provides the methods
savetofile and
loadfromfile
meikl ;-)
var F: TextFile;
begin
AssignFile(F,'sample.txt')
Rewrite(F);
try
WriteLn(F,'line of string');
finally
CloseFile(F);
end;
end;
ziolko.