0

I'm using Delphi XE2 and I'm having an issue where upon selecting an option from a DBLookupCombo box a modal dialog will display.

However a problem is occurring whereby when the modal dialog is displayed, the LookupCombo will remain on top of the Modal Dialog.

It's only a minor cosmetic issue but it's driving me mad. Programatically using 'SendToBack' on the combo has no effect.

Is there anything else I can do with regards to this issue?

Code Snippet:

   else if (getUserName  <> cboUserName.Text) and (userHasPerm2 = 1) then
   begin

    ValidUser := false;
    frmValidateUser := TfrmValidateUser.Create(self);
    frmValidateUser.txtUsername.ReadOnly := true;
    frmValidateUser.txtUsername.enabled := false;
    frmValidateUser.FormStyle := fsStayOnTop;
    cboUsername.SendToBack;
    frmValidateUser.ShowModal;

So if the user selected isn't the logged in user and doesn't have appropriate permissions, the ValidateUser form will display modally. As you can see I've tried setting the from style to 'stay on top' and the combobox to 'sendtoback' without success.

8
  • What happens if you click on the modal dialog?
    – Imanuel
    Dec 31, 2012 at 10:25
  • You can click and drag the Modal Dialog away from underneath the ComboBox but it's still annoying to have to do this. I assumed using 'SendToBack' would sort this issue out but it seems not.
    – coopertkm
    Dec 31, 2012 at 10:30
  • I think SendToBack only changes the order of components within a parent component, i.e. a TForm. Does clicking 1. the ComboBox and 2. the ModalDialog change something? Is the Combobox still active - can you change it while the ModalDialog is visible?
    – Imanuel
    Dec 31, 2012 at 10:32
  • Once an item on the Combobox has been selected and the ModalDialog is visible the Combobox is no longer active. Ideally in this situation the Combobox should 'close up' or at the very least remain underneath the ModalDialog while that's displayed.
    – coopertkm
    Dec 31, 2012 at 10:36
  • I don't know why that happens. You should post your code, where and how do you show the modal window?
    – Imanuel
    Dec 31, 2012 at 10:39

1 Answer 1

0

The popup window (the dropdown rectangle) behave like this. Sending the combobox to the back does not help, as the modal dialog does not know this.

You could try to set the frmValidateUser.FormStyle to fsStayOnTop. If this does not help, then you have to tell Windows to set the dialog to be at the very top:

SetWindowPos(frmValidateUser.Handle, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE+SWP_NOSIZE);

But to be honest, it's not a good solution. This dialog will also hide any other topmost messages which might pop up from other applications or even Windows itself.

Why don't you try to let the dialog popup after the dropdown disappears?

Update: I tried to replicate the problem, by creating a simple form having only one combobox on it. In the OnSelect-Event of the combobox I simply create a new instance of the same form and make it appear at the same coordinates as the combobox;

procedure TForm1.ComboBoxSelect(Sender: TObject);
Var
  f : TForm1;
  p : TPoint;
begin
  f := TForm1.Create(nil);
  p := ComboBox.ClientToScreen(point(0,0));
  f.Left := p.x;
  f.Top := p.y;
  f.ShowModal;
end;

(Excuse the silly variable names, but for a simple test like this, I thought it'd be ok).

The application works as expected. After having selected an entry, the dropdown disappears and the new form is displayed.

4
  • I've worked around the issue by hiding the drop-down combobox once an item has been selected.
    – coopertkm
    Dec 31, 2012 at 11:46
  • Which event do you use? If I use 'OnSelect', everything works fine.
    – alzaimar
    Dec 31, 2012 at 13:08
  • "p := f.Left := ComboBox.ClientToScreen(point(0,0));" Surprise, I should remember that. On second thought, the code gets less readable.
    – Jan Doggen
    Jan 1, 2013 at 12:28
  • @JanDoggen: Well... hmmm... think so? Ok. ;-) Fixed. Thanks
    – alzaimar
    Jan 1, 2013 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.