How do I get Welcome Page browser navigate to some URI from within OTA package wizard?

假装没事ソ 提交于 2019-12-06 20:50:33

问题


What I'm trying to do is to create an ability to view (not to edit) the HTML pages included into project. The Welcome Page already has embedded web browser, so it appears to be a good candidate for that.

Curios why? Here is a question with background info.


回答1:


In case you're willing to use a hack like this:

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;

Cons:

  • it's a hack (startpageidexx.bpl is not exposed through the API or documented)
  • it's hard-coded for Delphi XE (you need a different file name for other versions, the method signature might be different, too - e.g. in older AnsiString versions)
  • it does nothing if there is no edit window (there has to be at least one open module)
  • it always opens a new browser view

EDIT: It seems to be possible to reuse an existing open Welcome page, as well as make this hack compatible with older versions of Delphi. The following shows two alternatives, Delphi XE and Delphi 2007 (both seem to be working):

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;

Remaining cons:

  • it's still a hack
  • it's still hard-coded, for Delphi XE (Unicode) and Delphi 2007 (ANSI)
  • it still does nothing if there is no edit window

Perhaps you can use this as a start if you need compatibility for other versions.




回答2:


Here is a solution I've made specifically for you...

Download the source from here, extract and load the package in Delphi (I made it in Delphi XE, but it'll load in any version! You will need to change the Unit Output path in Project Options on pre-XE versions, though)... install the package.

In the Help menu, find Create Browser and click it. This will then create and display a tab which navigates to my blog (for the purpose of example).

You can easily modify this to suit your needs! The Help Menu Item code is located in EditWizard.MenuItem.pas, and can be disregarded! Just note that it's making a call when clicked to (BorlandIDEServices as IOTAEditorViewServices).ShowEditorView(CreateTab('http://www.simonjstuart.com'));, which is what actually creates a browser tab instance!

All the code for the Browser Tab (including its Frame layout) is contained in EditorWizard.Frame.pas, which makes it really easy to modify to suit your needs!

The unit EditorWizard.Wizard.pas contains the small amount of code needed to register the custom browser tab into the IDE.

Some tweaking will of course be required on your part, but this should certainly serve as a very acceptable base for what you're trying to do.

Enjoy :)




回答3:


You are better off displaying your own TForm with a TWebBrowser component on it that you can load HTML into.



来源:https://stackoverflow.com/questions/8072949/how-do-i-get-welcome-page-browser-navigate-to-some-uri-from-within-ota-package

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