私はdelphiIDEの専門家で働いており、Delphi IDEによって表示されるすべてのフォームを列挙する必要があります。現在、Screen.Forms
プロパティを使用していますが、OTAを使用してこれを行う別の方法があるかどうか疑問に思っています。Screen.Forms
私のエキスパートがBPLである場合にのみ機能するためですが、現在はdllエキスパートに移行しています。
2 に答える
8
Screen.Forms
DLLから引き続き機能するはずです。「ランタイムパッケージを使用する」リンカーオプションを選択してDLLをコンパイルするようにしてください。そうすれば、DLLはIDEと同じVCLインスタンスを使用し、を含むすべての同じグローバル変数にアクセスできるようになりますScreen
。
于 2011-05-29T21:55:41.707 に答える
2
これは、OpenToolsAPIで完全に可能です。
IDEで開いているすべてのフォームのリストを抽出するには、次のようなものを使用できます。
procedure GetOpenForms(List: TStrings);
var
Services: IOTAModuleServices;
I: Integer;
Module: IOTAModule;
J: Integer;
Editor: IOTAEditor;
FormEditor: IOTAFormEditor;
begin
if (BorlandIDEServices <> nil) and (List <> nil) then
begin
Services := BorlandIDEServices as IOTAModuleServices;
for I := 0 to Services.ModuleCount - 1 do
begin
Module := Services.Modules[I];
for J := 0 to Module.ModuleFileCount - 1 do
begin
Editor := Module.ModuleFileEditors[J];
if Assigned(Editor) then
if Supports(Editor, IOTAFormEditor, FormEditor) then
List.AddObject(FormEditor.FileName,
(Pointer(FormEditor.GetRootComponent)));
end;
end;
end;
end;
そのStringList内のポインターはIOTAComponentであることに注意してください。これをTFormインスタンスに解決するには、さらに深く掘り下げる必要があります。つづく。
次のように、IOTAIDENotifierタイプの通知機能をIOTAServicesに追加することにより、IDEで開かれているすべてのフォームを追跡することもできます。
type
TFormNotifier = class(TNotifierObject, IOTAIDENotifier)
public
procedure AfterCompile(Succeeded: Boolean);
procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean);
procedure FileNotification(NotifyCode: TOTAFileNotification;
const FileName: String; var Cancel: Boolean);
end;
procedure Register;
implementation
var
IdeNotifierIndex: Integer = -1;
procedure Register;
var
Services: IOTAServices;
begin
if BorlandIDEServices <> nil then
begin
Services := BorlandIDEServices as IOTAServices;
IdeNotifierIndex := Services.AddNotifier(TFormNotifier.Create);
end;
end;
procedure RemoveIdeNotifier;
var
Services: IOTAServices;
begin
if IdeNotifierIndex <> -1 then
begin
Services := BorlandIDEServices as IOTAServices;
Services.RemoveNotifier(IdeNotifierIndex);
end;
end;
{ TFormNotifier }
procedure TFormNotifier.AfterCompile(Succeeded: Boolean);
begin
// Do nothing
end;
procedure TFormNotifier.BeforeCompile(const Project: IOTAProject;
var Cancel: Boolean);
begin
// Do nothing
end;
procedure TFormNotifier.FileNotification(NotifyCode: TOTAFileNotification;
const FileName: String; var Cancel: Boolean);
begin
if BorlandIDEServices <> nil then
if (NotifyCode = ofnFileOpening) then
begin
//...
end;
end;
initialization
finalization
RemoveIdeNotifier;
end.
于 2011-05-29T21:59:29.870 に答える