Home WebBrowser not assigned
Reply: 2

WebBrowser not assigned

Anderson Muniz
1#
Anderson Muniz Published in 2017-01-15 02:46:43Z

I am using Delphi Xe4 with google maps library. I created a sample application which the customers address on dbgrid.

On dbgrid event I did

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;

But when I do a double click it shows me the message : webbrowser not assinged.

How Can I solve this ?

Best Anderson

John Easley
2#
John Easley Reply to 2017-01-15 04:19:09Z

Before adding items to the map via GMMarker1, you need to be sure that the Geocoder returns valid coordinates. Once you have valid coordinates, the GMMarker1 component expects that you add a marker using the latitude and longitude from the Geocoder. Try this:

   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;
Bhargav Rao
3#
Bhargav Rao Reply to 2017-01-19 09:21:43Z

I changed the dbgrid double click to:

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; 

and it worked.

Now, when I click on any line on dbgrid shows on google map inside the webbrowser.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304513 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO