tags:

views:

625

answers:

2

I'm writing a property editor for Delphi and I would like it to show up on the correct screen for multi-monitor support. In order to position it, I would like a reference to the "main" form for the Delphi IDE.

I've tried using the Application's MainForm property, and the Application object itself, but neither seems to work. I believe this is because the MainForm is actually the hidden TApplication instance referenced in this article by Nathanial Woolls (search for "application form"):

http://www.installationexcellence.com/articles/VistaWithDelphi/Original/Index.html

Does anyone know how to get a handle to the visible main form for the IDE. I'm trying to avoid something cheesy like iterating all forms and searching for "CodeGear RAD Studio" in the caption.

+2  A: 

IIRC the main form is called TAppBuilder, so something like FindWindow('TAppBuilder',nil) might be a starting point for you.

Ulrich Gerhardt
+2  A: 

The IDE's main form is Application.MainForm. My quick test design package:

procedure DoStuff(Form: TCustomForm);
var
  S: string;
begin
  S := Form.Caption;
  Form.Caption := S + ' - this one';
  try
    ShowMessage(Format('%s [%s] on monitor %d', [Form.Name, Form.ClassName, Form.Monitor.MonitorNum]));
  finally
    Form.Caption := S;
  end;
end;

initialization
  DoStuff(Application.MainForm);

This in my case displays "AppBuilder [TAppBuilder] on monitor 0" and I can see the " - this one" suffix in the main form's caption. What doesn't seem to work in your case?

TOndrej
I'm assigning it as an owner of a form, then trying to use Form.Position to correctly position the form to poOwnerCenter. When I get in to work I'll verify I'm getting the correct form and check the Form.Monitor property like you did. Thanks!
Jeremy Mullin
I got it working, it was a scope issue. I was referencing Application.MainForm not in my design time BPL, but in a DLL that it had loaded. In that scope it was returning nil. I couldn't use the TForm.Position property on forms created inside the DLL (I'm assuming for the same scoping reason), but I was able to use the Application.MainForm.Monitor position and dimensions retrieved while in the BPL to manually position the form. Thanks for the push in the right direction!
Jeremy Mullin