We're trying to put together an FNC Maps application (VCL, Delphi Seattle, FNC Maps 1.0.4.1) as a DLL.
All works fine until we implement either directions or geocoding. The below code runs fine when ran as an EXE, but does not when implemented as a DLL. Directions / Polylines are drawn, but when returning to the calling application, the program locks up. It seems like the DLL is unable to unload.
const
API_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX';
type
TFMain = class(TForm)
TMSFNCGoogleMaps1: TTMSFNCGoogleMaps;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure DoGetDirections(Sender: TObject; const ARequest:
TTMSFNCDirectionsRequest; const ARequestResult: TTMSFNCCloudBaseRequestResult);
private
{ Private declarations }
FDirections : TTMSFNCDirections;
public
{ Public declarations }
end;
var
FMain: TFMain;
implementation
{$R *.dfm}
procedure TFMain.DoGetDirections(Sender: TObject;
const ARequest: TTMSFNCDirectionsRequest;
const ARequestResult: TTMSFNCCloudBaseRequestResult);
var
its: TTMSFNCDirectionsItems;
it: TTMSFNCDirectionsItem;
I: Integer;
begin
TMSFNCGoogleMaps1.BeginUpdate;
TMSFNCGoogleMaps1.CloseAllPopups;
TMSFNCGoogleMaps1.ClearPolylines;
its := ARequest.Items;
for I := 0 to its.Count - 1 do
begin
it := its[I];
if it.Coordinates.Count > 0 then
TMSFNCGoogleMaps1.AddPolyline(it.Coordinates.ToArray).StrokeColor := gcRed;
end;
TMSFNCGoogleMaps1.EndUpdate;
end;
procedure TFMain.FormCreate(Sender: TObject);
begin
TMSFNCGoogleMaps1.APIKey := API_KEY;
FDirections := TTMSFNCDirections.Create(nil);
FDirections.APIKey := API_KEY;
FDirections.Service := dsGoogle;
FDirections.OnGetDirections := DoGetDirections;
end;
procedure TFMain.FormShow(Sender: TObject);
var
FOrigin : TTMSFNCMapsCoordinateRec;
FDest : TTMSFNCMapsCoordinateRec;
begin
TMSFNCGoogleMaps1.AddMarker(33, -110, 'Stop 1', '');
TMSFNCGoogleMaps1.AddMarker(40.560001, -74.290001, 'Stop 2', '');
FOrigin.Latitude := 33;
FOrigin.Longitude := -110;
FDest.Latitude := 40.560001;
FDest.Longitude := -74.290001;
FDirections.GetDirections(FOrigin, FDest); //comment out this line and all works fine
end;
From DLL project
procedure LaunchGoogleMap(AppHandle : Integer);
var
F : TFMain;
begin
try
F := TFMain.Create(nil);
try
F.ShowModal;
finally
F.Free;
end;
finally
end;
end;
Exports
LaunchGoogleMap index 1;