1
votes

I'm currently using Inno Setup to create an installer, this requires a google map. for the Map I am using TLama's inno-web-browser.

So I have a custom InputQueryPage displaying a google map. along with 2 input boxes for latitude and longitude when the user clicks on the map it shows the coordinates in an info window. Is it possible to parse the coordinates so that the 2 input boxes above can be populated from the the map with the lat and long ? the above can then hopefully be written to the registry as a in float format. but that is another question..

thanks for any replies regarding this..

1
This would require specific JavaScript interop which is not easy to implement. Parsing the document and reading the position from that info window is an option, but it's clumsy and except that you would not get notified when the user clicked the map. What about creating those edit boxes in JavaScript and reading their values by parsing the DOM ? That would be better than reading from the info window as you would know their IDs won't change. - TLama
TLama, Firstly can I just thank you, as I would never have got this far with various Inno installers if it was not for your answers on this site... Time to go and learn some JavaScript.. as I have never used JavaScript before... - Atlas
I've just commited version that exposes browser's OleObject through which you can access its document (search for a Delphi example that is using TWebBrowser.OleObject.Document.GetElementByID('ElementId')..., the same OleObject you can get by the WebBrowserGetOleObject function in this version). - TLama
Well I've been trying to work this out for 2 days and got nowhere TLama could you please provide an example of how to use the WebBrowserGetOleObject.. - Atlas
Done. The JavaScript synchronization between the Google Maps API and the input boxes I'll leave on you. - TLama

1 Answers

1
votes

What you're asking would require specific JavaScript interop which is not easy to implement. Hence I would suggest you making those edit boxes in JavaScript from where you will interop with the Google Maps API and read the values once you leave the page with the browser. I've added the access to the OleObject through the new WebBrowserGetOleObject function to the plugin.

Here is an example JavaScript with 2 input boxes (that you will synchronize from Google Maps API in your script). This script is in the following example referred by the fixed file name (in real change that to a temporary file extracted from the setup package):

<!DOCTYPE html>
<html>
<body>
  <input id="latinput" type="text">
  <input id="loninput" type="text">
</body>
</html>

In Inno Setup you can then read values from those input boxes this way:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Files]
Source:"WebBrowser.dll"; Flags: dontcopy

[Code]
const
  EVENT_BEFORE_NAVIGATE = 1;
  EVENT_FRAME_COMPLETE = 2;
  EVENT_DOCUMENT_COMPLETE = 3;

type
  TWebBrowserEventProc = procedure(EventCode: Integer; URL: WideString);

procedure WebBrowserCreate(ParentWnd: HWND; Left, Top, Width, Height: Integer; 
  CallbackProc: TWebBrowserEventProc);
  external 'WebBrowserCreate@files:webbrowser.dll stdcall';
procedure WebBrowserDestroy;
  external 'WebBrowserDestroy@files:webbrowser.dll stdcall';
procedure WebBrowserShow(Visible: Boolean);
  external 'WebBrowserShow@files:webbrowser.dll stdcall';
procedure WebBrowserNavigate(URL: WideString);
  external 'WebBrowserNavigate@files:webbrowser.dll stdcall';
function WebBrowserGetOleObject: Variant;
  external 'WebBrowserGetOleObject@files:webbrowser.dll stdcall';

var
  CustomPage: TWizardPage;

procedure InitializeWizard;
begin
  CustomPage := CreateCustomPage(wpWelcome, 'Web Browser Page', 
    'This page contains web browser');
  WebBrowserCreate(WizardForm.InnerPage.Handle, 0, WizardForm.Bevel1.Top, 
    WizardForm.InnerPage.ClientWidth, WizardForm.InnerPage.ClientHeight - WizardForm.Bevel1.Top, nil);
  WebBrowserNavigate('C:\AboveScript.html');
end;

procedure DeinitializeSetup;
begin
  WebBrowserDestroy;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  WebBrowserShow(CurPageID = CustomPage.ID);
end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
  Latitude: Variant;
  Longitude: Variant;
  OleObject: Variant;
begin
  Result := True;
  if CurPageID = CustomPage.ID then
  begin
    OleObject := WebBrowserGetOleObject;
    if not VarIsNull(OleObject) then
    begin
      Latitude := OleObject.Document.GetElementByID('latinput').value;
      Longitude := OleObject.Document.GetElementByID('loninput').value;
      MsgBox(Format('Lat: %s, Lon: %s', [Latitude, Longitude]), mbInformation, MB_OK);
    end;
  end;
end;