I noticed some strange behaviour when creating markers using the Google Map API for Delphi. I can easily reproduce the problem but have no explanation.
In the code below you will see a CreatePoint method, which I call in the OnClick event of a TButton. The marker is created as it should.
But then I call the SAME createpoint method with the same parameters in the OnCommandGet event of a IdHTTPServer. I then trigger the event by using Curl. But then the marker is not created and I get the message : "Access violation at address 5548985C in module 'mshtml.dll'. Read of address 00000144"
I don't understand why this could give a different result. Any idea ?
I'm using Delphi XE, so I create the TWebBrowser at runtime (because it's not in the Tool Palette in XE).
Code below, the sample project can be downloaded here.
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdCustomTCPServer, IdCustomHTTPServer,
IdHTTPServer, GMClasses, GMMap, GMMapVCL, ExtCtrls,
OleCtrls, SHDocVw, StdCtrls, GMLinkedComponents, GMMarker, GMMarkerVCL,
GMConstants, IdContext;
type
DeviceRange = 0..15;
TModWallyForm = class(TForm)
Panel1: TPanel;
GMMap1: TGMMap;
IdHTTPServer1: TIdHTTPServer;
GMMarker1: TGMMarker;
Button4: TButton;
procedure FormCreate(Sender: TObject);
procedure GMMap1AfterPageLoaded(Sender: TObject; First: Boolean);
procedure Button4Click(Sender: TObject);
procedure IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
private
{ Private declarations }
WebBrowser1 : TWebBrowser;
Marker : TGMMarker;
procedure CreatePoint(DeviceID : String; Longitude, Latitude : Real);
public
{ Public declarations }
end;
var
ModWallyForm: TModWallyForm;
implementation
{$R *.dfm}
procedure TModWallyForm.FormCreate(Sender: TObject);
var
i : Integer;
begin
WebBrowser1 := TWebBrowser.Create(Panel1);
TControl(WebBrowser1).Parent := Panel1;
WebBrowser1.Align := alClient;
GMMap1.WebBrowser := WebBrowser1;
// Instantiate Markers
Marker := TGMMarker.Create(nil);
Marker.Map := GMMap1;
IdHTTPServer1.Active := True;
end;
procedure TModWallyForm.GMMap1AfterPageLoaded(Sender: TObject; First: Boolean);
begin
if First then
begin
GMMap1.DoMap;
end;
end;
procedure TModWallyForm.Button4Click(Sender: TObject);
begin
CreatePoint('15',4.77,50.55900);
end;
procedure TModWallyForm.IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
CreatePoint('15',4.77,50.55900);
end;
procedure TModWallyForm.CreatePoint(DeviceID: string; Longitude: Real; Latitude: Real);
begin
with Marker.Add(Latitude, Longitude) do
begin
MarkerType := mtColored;
InfoWindow.HTMLContent := DeviceID;
ColoredMarker.Width := 48+(Index*20);
ColoredMarker.Height := 48;
ColoredMarker.PrimaryColor := clBlack;
ColoredMarker.StrokeColor := clBlack;
Title := ''; // Avoid showing the title when the mouse hovers over the marker
end;
GMMap1.RequiredProp.Center.Lat := Latitude;
GMMap1.RequiredProp.Center.Lng := Longitude;
GMMap1.RequiredProp.Zoom := 8;
end;
end.