Search code examples
delphicomboboxdelphi-2010

Delphi- combobox on toolbar


I am trying to put a combobox on a toolbar in Delphi 2010. The App is a MDI text editor. If I place a combobox on the toolbar and run the app, when I click the combobox, it opens up a new child window and doesn't drop down for a selection. I have tried putting the toolbar and combobox in both a controlbar and a coolbar, both with the same results. In fairness, I have not recreated the toolbar, just moved it to the other controls.

Has anyone seen this before and how do I get around it? I just tried it again with the same results. Here is the code for the combobox1.

procedure TMainForm.ComboBox1Change(Sender: TObject);
begin
  exec_sql(combobox1.Text);
end;

There is no on click for the toolbar and no button currently opens a new child.

The exec_sql looks like this:

procedure TMainForm.exec_sql(MachName:string);
var
  sql_str: string;
  parm_str: string;
begin
  mach.Free;
  parm_str := MachName;
  sql_str := 'Select * from machines where MACHINE_NAME = :parm_str';
  with adoquery1 do
  begin
    close;
    sql.Text := sql_str;
    with Parameters.ParamByName('parm_str') do
    begin
      DataType := ftString;
      Value := parm_str;
    end;
    open;
    mach := TMachineData.get_record_data(ADOQuery1);
  end;
  ShowMessage('Current Machine Is ' + mach.MACHINE_NAME);
end;

Solution

  • The problem was the combobox was firing the Form1.OnActivate event which created a new mdi child. OnActivate was set to ActionFirstChildExecute. I was creating a new blank child when the app opened. This had the described undesired effect. I removed the OnActivate and moved the ActionFirstChildExecute to OnShow. The app and combobox then worked as expected. There was nothing in the ActionFirstChildExecute to cause the behavior as shown in the code below. The problem was clicking the combobox fired the Form1.OnActivate event calling the code below.

    procedure TMainForm.ActionFirstChildExecute(Sender: TObject);
    var
    ChildForm: TMDIChild;
    begin
    Inc (Counter);
    ChildForm := TMDIChild.Create (Self);
    ChildForm.Caption := ('NONAME' + IntToStr(MDIChildCount));
    ChildForm.Show;
    (ActiveMDIChild as TMDIChild).FormCreate(Application);
    if ParamStr(1) <>'' then open_mru_item(ParamStr(1));
    end;