我想做的是创建一种能够查看(而不是编辑)项目中包含的HTML页面的能力。欢迎页已经嵌入了Web浏览器,因此它似乎是一个很好的选择。
为什么这样做呢?这里有一个带有背景信息的问题。
为什么这样做呢?这里有一个带有背景信息的问题。
以下是我为您特别制作的解决方案...
从这里下载源代码,然后在Delphi中加载该包(我是在Delphi XE中制作的,但它也可以在任何版本中加载!不过,在XE之前的版本中,您需要更改“项目选项”中的“单元输出路径”)... 然后安装这个包。
在帮助菜单中找到创建浏览器并单击它。然后会创建并显示一个选项卡,该选项卡导航到我的博客(只是为了示例而已)。
您可以轻松修改此选项卡以适应自己的需求!帮助菜单项代码位于EditWizard.MenuItem.pas
中,可以忽略!请注意,当单击时它调用的是 (BorlandIDEServices as IOTAEditorViewServices).ShowEditorView(CreateTab('http://www.simonjstuart.com'));
,这实际上是创建浏览器选项卡实例的代码!
所有与浏览器选项卡有关的代码(包括其框架布局)都包含在EditorWizard.Frame.pas
中,这使得对其进行修改以适应自己的需求变得非常容易!
单元EditorWizard.Wizard.pas
包含了注册自定义浏览器选项卡到IDE所需的少量代码。
当然,您需要进行一些微调,但这肯定可以作为您尝试实现的非常可接受的基础。
享受吧 :)
type
TOpenNewURLModule = procedure(const URL: string; EditorForm: TCustomForm);
procedure OpenURL(const URL: string);
var
EditWindow: INTAEditWindow;
Lib: HMODULE;
OpenNewURLModule: TOpenNewURLModule;
begin
EditWindow := (BorlandIDEServices as INTAEditorServices).TopEditWindow;
if not Assigned(EditWindow) or not Assigned(EditWindow.Form) then
Exit;
Lib := GetModuleHandle('startpageide150.bpl');
if Lib = 0 then
Exit;
OpenNewURLModule := GetProcAddress(Lib, '@Urlmodule@OpenNewURLModule$qqrx20System@UnicodeStringp22Editorform@TEditWindow');
if @OpenNewURLModule <> nil then
OpenNewURLModule(URL, EditWindow.Form);
end;
缺点:
编辑:似乎可以重用现有的打开的欢迎页面,并且使此hack与旧版Delphi兼容。以下显示了两个替代方案,Delphi XE和Delphi 2007(两者似乎都可以工作):
type
IURLModule = interface(IOTAModuleData)
['{9D215B02-6073-45DC-B007-1A2DBCE2D693}']
function GetURL: string;
procedure SetURL(const URL: string);
property URL: string read GetURL write SetURL;
end;
TOpenNewURLModule = procedure(const URL: string; EditorForm: TCustomForm);
function FindURLModule: IURLModule;
var
I: Integer;
begin
Result := nil;
with BorlandIDEServices as IOTAModuleServices do
for I := 0 to ModuleCount - 1 do
if Supports(Modules[I], IURLModule, Result) then
Break;
end;
procedure OpenURL(const URL: string; ReuseExistingView: Boolean = True);
{$IFDEF VER220} // Delphi XE
const
SStartPageIDE = 'startpageide150.bpl';
SOpenNewURLModule = '@Urlmodule@OpenNewURLModule$qqrx20System@UnicodeStringp22Editorform@TEditWindow';
{$ENDIF}
{$IFDEF VER185} // Delphi 2007
const
SStartPageIDE = 'startpageide100.bpl';
SOpenNewURLModule = '@Urlmodule@OpenNewURLModule$qqrx17System@AnsiStringp22Editorform@TEditWindow';
{$ENDIF}
var
Module: IURLModule;
EditWindow: INTAEditWindow;
Lib: HMODULE;
OpenNewURLModule: TOpenNewURLModule;
begin
EditWindow := nil;
Module := nil;
if ReuseExistingView then
Module := FindURLModule;
if Assigned(Module) then
begin
Module.URL := URL;
(Module as IOTAModule).Show;
end
else
begin
{$IFDEF VER220}
EditWindow := (BorlandIDEServices as INTAEditorServices).TopEditWindow;
{$ENDIF}
{$IFDEF VER185}
if Assigned((BorlandIDEServices as IOTAEditorServices).TopView) then
EditWindow := (BorlandIDEServices as IOTAEditorServices).TopView.GetEditWindow;
{$ENDIF}
if not Assigned(EditWindow) or not Assigned(EditWindow.Form) then
Exit;
Lib := GetModuleHandle(SStartPageIDE);
if Lib = 0 then
Exit;
OpenNewURLModule := GetProcAddress(Lib, SOpenNewURLModule);
if @OpenNewURLModule <> nil then
OpenNewURLModule(URL, EditWindow.Form);
end;
end;
剩余的不足之处:
如果您需要兼容其他版本,也许可以将此作为起点。
function KeyCodeToShortCut(KeyCode: Integer): TShortCut; overload; register; external 'coreide70.bpl' name '@Vedtypes@KeyCodeToShortCut$qqri';
。只有当我们能从 .bpl 重构出 .dcp 时,我们才能将它们用作包(再见,基于版本号的分支)... - OnTheFlyIURLModule
接口结构的呢? - OnTheFly(IOTAModule as TObject).ClassName
开始,然后使用GetProcAddress(lib, '@unitname@classname@')
获取类引用,再通过RTTI遍历祖先,获取实现的接口列表(GUID也存储在RTTI中)。当然,还有依赖项查看器和tdump startide150.bpl
。 - Ondrej Kelle最好使用带有TWebBrowser
组件的自己的TForm
来显示,您可以将HTML加载到其中。