Solved

Super easy question...

Posted on 1998-12-05
8
136 Views
Last Modified: 2010-04-06
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.
0
Comment
Question by:dokken
  • 4
  • 3
8 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 1349456
hi,
use loadfromfile with begin and end update ie:

application.processmessages;
memo1.lines.beginupdate;
memo1.lines.loadfromfile(c:\autoexec.bat);
memo1.lines.enupdate;

a good way to load a large file is to show a splash screen while its loading
Barry

0
 
LVL 17

Expert Comment

by:inthe
ID: 1349457
quick syntax check...


memo1.lines.beginupdate;
application.processmessages;
memo1.lines.loadfromfile('c:\autoexec.bat');
memo1.lines.endupdate;

Barry

0
 

Author Comment

by:dokken
ID: 1349458
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.
0
 

Author Comment

by:dokken
ID: 1349459
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.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 17

Expert Comment

by:inthe
ID: 1349460
hi
sorry ok what about

var
mystring:tstringlist;
begin
mystring:=tstringlist.create;
mystring.loadfromfile('c:\autoexec.bat');
{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?
0
 

Author Comment

by:dokken
ID: 1349461
Thats works great, put it as the answer so I can give you the points.

Thanks.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1349462
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(filename,fmOpenRead or fmShareDenyNone);
  try
    SetLength(str,s1.Size);
    s1.Read(PChar(str)^,s1.Size);
  finally s1.Free end;
  result:=true;
end;

Regards, Madshi.
0
 
LVL 17

Accepted Solution

by:
inthe earned 20 total points
ID: 1349463
as awnser:
var
mystring:tstringlist;
begin
mystring:=tstringlist.create;
mystring.loadfromfile('c:\autoexec.bat');
{do whatever with your string}
end

Barry
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now