Launch Map From DLL In Succession

Launching a Map with the new Route Calculator from a DLL in succession seems to (sort of) fail on the 2nd run.

DLL

procedure LaunchGoogleMap(AppHandle : Integer);
var
  F : TFMain;

  OldAppHandle : Integer;
begin
  OldAppHandle := Application.Handle;
  Application.Handle := AppHandle;

    try
      F := TFMain.Create(nil);
      try
        F.ShowModal;
      finally
        F.Free;
      end;
    finally
      Application.Handle := OldAppHandle;
    end;
end;

Exports
  LaunchGoogleMap index 1;

UMain/FMain

procedure TFMain.FormCreate(Sender: TObject);
begin
  TMSFNCGoogleMaps1.APIKey := API_KEY;
  TMSFNCRouteCalculator1.APIKey := API_KEY;
  TMSFNCRouteCalculator1.Active := True;
end;

procedure TFMain.FormShow(Sender: TObject);
begin
  TMSFNCRouteCalculator1.CalculateRoute('TUCSON, AZ', 'GREELEY, CO', nil, 'TheID', nil);
end;

Delphi Sydney / FNC Maps Version 2.1

If you supply a Callback method for CalculateRoute, you can see that the route is in fact calculated and returned. It's just the polyline does not get drawn.
GoogleMapsDLLRunTwice

If you move the CalculateRoute to the OnMapInitialized instead of the OnFormShow, the issue will be solved.

Seems to be working great. Thank you!

1 Like