Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening text files

Status
Not open for further replies.

ivoestg

Programmer
Mar 21, 2001
77
0
0
PT
Hi,

I need to open a text file, read the first line of it, and put its charachters in a string variable. how can i do this? thanks...

I'm in ivoestg@yahoo.com
 
The simplist way is to use a memo
e.g

var astring: string;
begin
memo1.lines.loadfromfile('your filename here');
astring := memo1.lines[0];
end;

steve



 
An alternative to using a memo is to use a TextFile variable. The following function accepts the file name as a parameter and returns the first line of the file as a string:

function ReadFirstLine(FileName: TFileName): String;
var
F: TextFile;
begin
AssignFile(F, FileName);
Reset(F);
Readln(F, Result);
CloseFile(F);
end;

Hope this helps.
Dave


nordicsys@aol.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top