Recent

Author Topic: Reading and writting a file into a list box not working so well.  (Read 4284 times)

captian jaster

  • Guest
Code: [Select]
procedure TForm1.OpenBtnClick(Sender: TObject);
begin
  AssignFile(SaveFile,'Records.txt');
  IF NOT(Fileexists('Records.txt'))Then ShowMessage('Records Not Found!')Else
  begin
    Reset(SaveFile);
    Repeat
      Readln(SaveFile,ReadStr);
      Form1.Box.Items.Add(ReadStr);
    until(EoF(SaveFile));
  end;
end; 
Normally yeah this should work and it does sometimes...
But in my program i can clear the list box. so when i click to clear it then i press the open button(its what this does) it raises an error and i dont know why. let me know if i have to post the whole code
thnx

captian jaster

  • Guest
Re: Reading and writting a file into a list box not working so well.
« Reply #1 on: May 08, 2010, 08:52:21 pm »
Never mind, i fixed it

Troodon

  • Sr. Member
  • ****
  • Posts: 484
Re: Reading and writting a file into a list box not working so well.
« Reply #2 on: May 08, 2010, 09:24:04 pm »
don't forget to close the file.
Lazarus/FPC on Linux

captian jaster

  • Guest
Re: Reading and writting a file into a list box not working so well.
« Reply #3 on: May 09, 2010, 01:03:57 am »
yeah thats what i forgot to do :)

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1918
Re: Reading and writting a file into a list box not working so well.
« Reply #4 on: May 09, 2010, 08:36:29 am »
This code does the same in one line:

Code: [Select]
  ListBox1.Items.LoadFromFile('Records.txt');

 

TinyPortal © 2005-2018