How can I get the Delphi IDE's Main Form?

你说的曾经没有我的故事 提交于 2019-12-22 10:33:02

问题


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.


回答1:


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?




回答2:


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



来源:https://stackoverflow.com/questions/967327/how-can-i-get-the-delphi-ides-main-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!