V
V
Vladimir Dubos2015-10-11 21:26:38
Delphi
Vladimir Dubos, 2015-10-11 21:26:38

How to generate a list from a text file in Delphi?

One of the noobs (me) has a list (ListBox) and a text file (children.txt), and when opening a window in the list should be formed from this file.
For example:
text file:
Pupkin Vasily
Fruktozyan Banani
list:
Pupkin Vasily
Fruktozyan Banani
, etc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mik92, 2015-10-11
@vovaduba

Global FName of type string;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ListBox1.Items.LoadFromFile(FName);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with OpenDialog1 do
  if Execute(Handle) then
    begin
    FName:= FileName;
    end;
end;

You can do whatever suits you. The key point in your case is the ListBox1.Items.LoadFromFile function with which you can load the contents of the .txt file into the ListBox.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question