I have a file containing one 5 letter word per line and x number of words total. How can I open the file and display all the words in a ListBox? I have had limited success with this code but it only adds the first line and if run more than once it returns an error;
var
myFile: TextFile;
S: string;
procedure TForm1.edtFirstChange(Sender: TObject);
begin
AssignFile(myFile, edtFirst.Text + '.txt');
Reset(myFile);
ReadLn(myFile, S);
ListBox1.Items.Text := S;
CloseFile(myFile);
end;
I have also tried the following to try to read all the way down to the eof but it doesn't work either
procedure TForm1.edtFirstChange(Sender: TObject);
begin
AssignFile(myFile, edtFirst.Text + '.txt');
Reset(myFile);
while not Eof(myFile) do
begin
ReadLn(myFile, S);
ListBox1.Items.Text := S;
CloseFile(myFile);
end;
end;
I have also tried ListBox1.Items.Add := S; instead of .Text but that returns a complier error. What am I doing wrong?
Thx
D
var
myFile: TextFile;
S: string;
procedure TForm1.edtFirstChange(Sender: TObject);
begin
AssignFile(myFile, edtFirst.Text + '.txt');
Reset(myFile);
ReadLn(myFile, S);
ListBox1.Items.Text := S;
CloseFile(myFile);
end;
I have also tried the following to try to read all the way down to the eof but it doesn't work either
procedure TForm1.edtFirstChange(Sender: TObject);
begin
AssignFile(myFile, edtFirst.Text + '.txt');
Reset(myFile);
while not Eof(myFile) do
begin
ReadLn(myFile, S);
ListBox1.Items.Text := S;
CloseFile(myFile);
end;
end;
I have also tried ListBox1.Items.Add := S; instead of .Text but that returns a complier error. What am I doing wrong?
Thx
D