Question

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;
Was it helpful?

Solution 2

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;

OTHER TIPS

I am unable to reproduce your problem. Here are the steps I took to try and do so:

  1. File->New->Other->Delphi Projects->MDI Application
  2. Created a new folder when prompted for the project
  3. Delphi shows a new MDI parent, with a toolbar, some toolbuttons, menu, etc.
  4. Dropped a new TComboBox on the toolbar
  5. Added 'Item 1', 'Item 2', and 'Item 3' to the combobox via the Object Inspector
  6. Ran the application, and clicked the dropdown button on the combobox.
  7. Picked any item from the combobox; it behaved as expected.
  8. Picked a different item from the combobox. It behaved as expected.

Therefore, the problem is not with placing a TComboBox on a TToolBar, and has to be elsewhere in your code, in a location not included in your question.

You'll need to use the debugger, set some breakpoints in various locations, and take a look at the call stack window to see how you got where you're at in the code. You can then set a new breakpoint in one of those earlier calls, repeat the process, and keep doing so until you trace back to the point that's causing your problem.

I just tested debugging in this fashion. I created a FormCreate event in the default CHILDWIN unit, added Dialogs to the implementation uses clause, and added a call to MessageDlg('New child created', mtInformation, [mbOK], 0); in that FormCreate event. I set a breakpoint there, and ran the app, and then clicked on the New toolbar button. When the breakpoint was triggered, the call stack window looked like this (I've highlighted the place that caused the new child window to be created - the line below it is relevant as well):

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top