hi, ive got a text file which has multiple lines, how can i display all the lines?

BEGIN
 assignfile(filea, user);
 reset(filea);
while not eof(filea)
 do
 BEGIN
   readln(filea,textstring);
 writeln(textstring);
 end;
 closefile(filea);
 readln;

 END

Thanks

Recommended Answers

All 7 Replies

by the looks of your code it should be doing that.

nope its just reading the first line

Why not use TStringList.LoadFromFile() ?

Also I don't know what effect writing a text file has after you read the line, are you trying to duplicate the lines of the file? Try commenting out your WriteLn() call and doing something else with the read-in string.

hey thanks for the answers, i kept looking on google and found the answer:)

all i had to do was write loads of
readln(filea,textstring);
writeln(textstring);

No, all you needed was the while loop ....

hey thanks for the answers, i kept looking on google and found the answer:)

all i had to do was write loads of
readln(filea,textstring);
writeln(textstring);

Typically when you find yourself copying and pasting code you have a design issue, and I believe that is the case here...

procedure TForm1.Button4Click(Sender: TObject);
Var
  FileA: TextFile;
  fName, fOut: String;
begin
  fName := 'C:\test.txt';
  AssignFile(FileA, fName);
  Reset(FileA);
  while not eof(FileA) do
  begin
    ReadLn(FileA, fOut);
    WriteLn(fOut);
  end;
 CloseFile(FileA);
end;

The above code will write the entire contents of a file, line by line, out to the command prompt. If you are not using the output type as a console application it will generate I/O error 105.

I don't see what the problem is.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.