Read lines from a Txt file and play in different Edits

Asked

Viewed 1,983 times

-2

I have the following structure of .Txt:

--------DEF--------
3
25
3
2
46
------PROF1----------
0-20 cm
100%
100%
100%
10%
33%
0%
100%
0%
Outro

I would like it when the user chooses the option of .Txt in the comboBox, that was equal to the file name it threw the value of each line into a different Edit something like this:

Edit1.text = linha 2
edit2.text = linha 3 
...
  • I didn’t quite understand your question. You can explain it better?

1 answer

2


try:

procedure TForm1.btnProcessarClick(Sender: TObject);
var
   stlArquivo: TStringList;
begin
   stlArquivo := nil;
   try
      stlArquivo := TStringList.Create;
      stlArquivo.LoadFromFile('seuarquivo.txt');
      edtNome.Text := stlArquivo[1];
      edtSobrenome.Text := stlArquivo[2];
   finally
      if Assigned(stlArquivo) then FreeAndNil(stlArquivo);
   end;
end;
  • perfect, thank you.

  • if it were a file. ini would be easy.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.