Page 1 of 1

Delphi ComboBox Items

PostPosted: November 4th, 2008, 6:29 pm
by kulverstukas
Hello, im writing some app, and im stuck at ComboBox'es. The idea is, that when you click on a Item, that is in the ComboBox, the program must read the Text file, named by the Item name in the ComboBox, and output the content of the Text file in the MemoBox :confused: .
So, the question is, how to make the Item in the ComboBox display contents of Text file #-o
Thanks ;)

Re: Delphi ComboBox Items

PostPosted: November 4th, 2008, 7:35 pm
by Kambiz
If your ComboBox contains file names, you can use the following code:

Code: Select all
procedure TForm1.ComboBox1Change(Sender: TObject);
var
  FileName: String;
begin
  if ComboBox1.ItemIndex >= 0 then
  begin
    FileName := ComboBox1.Items[ComboBox1.ItemIndex];
    Memo1.Lines.LoadFromFile(FileName);
  end;
end;


Assign both OnChange and OnClick events of the ComboBox to the event handler.