tags:

views:

2245

answers:

5

I have a Delphi 7 application that has two views of a document (e.g. a WYSIWYG HTML edit might have a WYSIWYG view and a source view - not my real application). They can be opened in separate windows, or docked into tabs in the main window.

If I open a modal dialog from one of the separate forms, the main form is brought to the front, and is shown as the selected window in the windows taskbar. Say the main form is the WYSIWYG view, and the source view is poped out. You go to a particular point in the source view and insert an image tag. A dialog appears to allow you to select and enter the properties you want for the image. If the WYSIWYG view and the source view overlap, the WYSIWYG view will be brought to the front and the source view is hidden. Once the dialog is dismissed, the source view comes back into sight.

I've tried setting the owner and the ParentWindow properties to the form it is related to:

dialog := TDialogForm.Create( parentForm );
dialog.ParentWindow := parentForm.Handle;

How can I fix this problem? What else should I be trying?

Given that people seem to be stumbling on my example, perhaps I can try with a better example: a text editor that allows you to have more than one file open at the same time. The files you have open are either in tabs (like in the Delphi IDE) or in its own window. Suppose the user brings up the spell check dialog or the find dialog. What happens, is that if the file is being editing in its own window, that window is sent to below the main form in the z-order when the modal dialog is shown; once the dialog is closed, it is returned to its original z-order.

Note: If you are using Delphi 7 and looking for a solution to this problem, see my answer lower down on the page to see what I ended up doing.

A: 

First of all, I am not completely sure I follow, you might need to provide some additional details to help us understand what is happening and what the problem is. I guess I am not sure I understand exactly what you're trying to accomplish and what the problem is.

Second, you shouldn't need to set the dialog's parent since that is essentially what is happening with the call to Create (passing the parent). The dialogs you're describing sound like they could use some "re-thinking" a bit to be honest. Is this dialog to enter the properties of the image a child of the source window, or the WYSIWYG window?

Ryan Farley
+1  A: 

Is the dialog shown using ShowModal or just Show? You should probably set the PopupMode property correct of the your dialog. pmAuto would probably your best choice. Also see if you need to set the PopupParent property.

Lars Truijens
+2  A: 

I'd use this code... (Basically what Lars said)

dialog := TDialogForm.Create( parentForm );
dialog.PopupParent := parentForm;
dialog.PopupMode   := pmExplicit; 
dialog.ShowModal();
Marius
A: 

I'm not sure I quite understand what you are getting at, but here's a few things I can suggest you can try...

  1. This behaviour changes between different versions of Delphi. I'd suggest that this is due to the hoops they jumped through to support Windows Vista in Delphi 2007.
  2. If you are using Delphi 2007, try removing the line from the project source file that sets the Application.MainFormOnTaskBar boolean variable.
  3. With this removed, you should be able to use the various Form's BringToFront / SendToBack methods to achieve the Z-ordering that you are after.

I suspect that what you've discovered has been discussed on this link Of course, I may have just missed your point entirely, so apologies in advance!

Andrew
+1  A: 

I ultimately ended up finding the answer using Google Groups. In a nutshell, all the modal dialogs need to have the following added to them:


procedure TDialogForm.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.Style := Params.Style or WS_POPUP;
  Params.WndParent := (Owner as TWinControl).Handle;
end;

I'm guessing this does the equivalent of Lars' and Marius' answers in Delphi 7.

garethm