dokken
asked on
Super easy question...
I'm new to Delphi and would like to know how to read a text file into a string. It has to be fast because the file it's reading could be over 5 MB's.
Thanks.
Thanks.
quick syntax check...
memo1.lines.beginupdate;
application.processmessage s;
memo1.lines.loadfromfile(' c:\autoexe c.bat');
memo1.lines.endupdate;
Barry
memo1.lines.beginupdate;
application.processmessage
memo1.lines.loadfromfile('
memo1.lines.endupdate;
Barry
ASKER
I already know how to load it into a memo and rich text box... but I only want it load into a string. The file is going to get very big, so I don't want any limitations or anything slowing it down.
ASKER
Or, what might be better, if the rich text box's savetofile can save the text as text and not RTF and handle over 200,000 lines.
hi
sorry ok what about
var
mystring:tstringlist;
begin
mystring:=tstringlist.crea te;
mystring.loadfromfile('c:\ autoexec.b at');
{do whatever with your string}
end
this will read your file into 'mystring' im memory and should be quite fast enough, the size wont be a prob stringlists can handle up to 2gig.
is this more on the right lines for your question?
sorry ok what about
var
mystring:tstringlist;
begin
mystring:=tstringlist.crea
mystring.loadfromfile('c:\
{do whatever with your string}
end
this will read your file into 'mystring' im memory and should be quite fast enough, the size wont be a prob stringlists can handle up to 2gig.
is this more on the right lines for your question?
ASKER
Thats works great, put it as the answer so I can give you the points.
Thanks.
Thanks.
Or is it this what you want? It's the fastest way I can think of...
function LoadStrFromFile(filename: string; var str: string) : boolean;
var s1 : TFileStream;
begin
result:=false;
if not fio_FileExists(filename) then exit;
s1:=TFileStream.Create(fil ename,fmOp enRead or fmShareDenyNone);
try
SetLength(str,s1.Size);
s1.Read(PChar(str)^,s1.Siz e);
finally s1.Free end;
result:=true;
end;
Regards, Madshi.
function LoadStrFromFile(filename: string; var str: string) : boolean;
var s1 : TFileStream;
begin
result:=false;
if not fio_FileExists(filename) then exit;
s1:=TFileStream.Create(fil
try
SetLength(str,s1.Size);
s1.Read(PChar(str)^,s1.Siz
finally s1.Free end;
result:=true;
end;
Regards, Madshi.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
use loadfromfile with begin and end update ie:
application.processmessage
memo1.lines.beginupdate;
memo1.lines.loadfromfile(c
memo1.lines.enupdate;
a good way to load a large file is to show a splash screen while its loading
Barry