双击时出现错误消息 "WebBrowser not assigned"

Error message "WebBrowser not assigned" on a double click

我正在使用 Delphi XE4 和 Google 地图库。我创建了一个客户在 dbgrid 上解决的示例应用程序。

在我做的 dbgrid 事件中:

procedure TForm1.DBGrid1DblClick(Sender: TObject);
var
    endereco : string;
    pesquisarendereco : string;

begin

    WebBrowser1.Enabled := True;
    GMMap1.Active := True;

    if dsClienteEndereco.DataSet.RecordCount > 0 then
    begin
        GMGeoCode1.Geocode(qryClienteEndereco.FieldByName('ENDERECORESIDENCIA').AsString);
        endereco := qryClienteEnderecoENDERECORESIDENCIA.Value;

        GMMarker1.Items[dsClienteEndereco.DataSet.Recno].CenterMapToMarker;

        pesquisarendereco := 'http://maps.google.com/maps?q=' + endereco;
        WebBrowser1.Navigate(pesquisarendereco);
    end;
end;

但是当我双击时,它会显示消息:

webbrowser not assigned.

我该如何解决这个问题?

在通过 GMMarker1 将项目添加到地图之前,您需要确保 Geocoder returns 有效坐标。获得有效坐标后,GMMarker1 组件希望您使用 Geocoder 中的纬度和经度添加标记。试试这个:

   WebBrowser1.Enabled := True;
   GMMarker1.Map := GMMap1;
   GMMap1.WebBrower := WebBrowser1;
   GMMap1.Active := True;

    if dsClienteEndereco.DataSet.RecordCount > 0 then
    begin

      GMGeoCode1.Geocode(qryClienteEndereco.FieldByName('ENDERECORESIDENCIA').AsString);
      If GmGeoCode1.Count <> 0 then
      begin   
        endereco := qryClienteEnderecoENDERECORESIDENCIA.Value;
        GMMarker1.Add(GmGeoCode1[0].Geometry.Location.Lat, GmGeoCode1[0].Geometry.Location.Lng, endereco);
        GMMarker1.items[GMMarker1.Count-1].CenterMapToMarker;

        // you shouldn't need these lines, the WebBrowser should navigate on its own
        //pesquisarendereco:='http://maps.google.com/maps?q='+endereco;
        //WebBrowser1.Navigate(pesquisarendereco);
      end;

    end;

我将 dbgrid 双击更改为:

procedure TformHistoricoRotas.DBGrid1DblClick(Sender: TObject);

var
    endereco: string;
    pesquisarendereco: string;
    Marker: TMarker;

begin

    WebBrowser1.Enabled := True;
    GMMarker1.Map := GMMap1;
    GMMap1.WebBrowser := WebBrowser1;

    GMMap1.Active := True;
    if dsClienteEndereco.DataSet.RecordCount > 0 then
    begin
        GMGeoCode1.Geocode(qryClienteEndereco.FieldByName('ENDERECORESIDENCIA').AsString);
        If GmGeoCode1.Count <> 0 then
        begin
            endereco := IntToStr(qryClienteEnderecoPRIORIDADE.Value) + ', ' + qryClienteEnderecoCHECKOUT.Value + ', ' + qryClienteEnderecoENDERECORESIDENCIA.Value;
            GMMarker1.Add(GmGeoCode1[0].Geometry.Location.Lat, GmGeoCode1[0].Geometry.Location.Lng, endereco);
            //GMMarker1.Add(GmGeoCode1[0].Geometry.Location.Lat, GmGeoCode1[0].Geometry.Location.Lng, endereco);
            GMMarker1.items[GMMarker1.Count-1].CenterMapToMarker;
            GMMap1.Precision := 30;
        end;
    end;
end;

成功了。

现在,当我单击 dbgrid 上的任何行时,它会显示在网络浏览器内的 Google 地图上。