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

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);

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.

This article has been dead for over six months. Start a new discussion instead.