Delphi ComboBox Items

Please discuss general Delphi programming topics here.

Delphi ComboBox Items

Postby kulverstukas » November 4th, 2008, 6:29 pm

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 ;)
kulverstukas
Member
Member
 
Posts: 1
Joined: November 4th, 2008, 5:58 pm

Re: Delphi ComboBox Items

Postby Kambiz » November 4th, 2008, 7:35 pm

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.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 3 guests

cron