Remove part of a text in the combobox

Asked

Viewed 127 times

1

I have a combobox that I read a directory and bring the names of the found files:

exit:

demons.txt 
arch.txt 
elo.txt

So far so good, but I would not like the extension to appear in the combobox .txt, how to remove it?

1 answer

1


You can use the function TPath.GetFileNameWithoutExtension:

Uses
  IOUtils;
// ....

procedure TForm1.FormCreate(Sender: TObject);
const
   Arquivos: array[1..3] of string = ('demons.txt ','arch.txt ','elo.txt');
Var
   Arquivo: String;
begin
  ComboBox1.Clear;
  For Arquivo in Arquivos do 
  begin
    ComboBox1.Items.Add(TPath.GetFileNameWithoutExtension(Arquivo));
  end;
end;
  • 1

    if you had for example x files, which can be generated, deleted...

  • I fill the combo box with a Tstringlist, how could I pass it as parameter?

  • @Guilhermelima Just go through the StringList and add to the Combobox the current item using this function. See: http://pastebin.com/tqvT1B2v

  • solved, thank you :D

Browser other questions tagged

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