How do I send data between Javascript and Delphi?

I am trying to populate an array in my Delphi program with data produced by Javascript.

I have a WebBrowser that has loaded HTML with the following Javascript:

function DrawTrack () {
  var geo_path = new Array ();
      var geo_path = [
          new google.maps.LatLng (-18.142599, 178.431),
      new google.maps.LatLng (-27.46758, 153.027892)
      ];
    var Track = new google.maps.Polyline ({
      path: geo_path,
      strokeColor: "# FF0000",
      strokeOpacity: 1.0,
      strokeWeight: 2
        });

  Track.setMap (map);
}

I would like to add a button with an OnClick handler that would call

HTMLWindow2.execScript ('DrawTrack ()', 'JavaScript')

The function would create a line of 2-um coordinates.

How can I achieve my goal?

Answers:

Answer

You must rewrite your JavaScript function to accept parameters

function DrawTrack (FromLat, FromLng, ToLat, ToLng) {
  var geo_path = new Array ();
      var geo_path = [
          new google.maps.LatLng (FromLat, FromLng),
      new google.maps.LatLng (ToLat, ToLng)
      ];
    var Track = new google.maps.Polyline ({
      path: geo_path,
      strokeColor: "# FF0000",
      strokeOpacity: 1.0,
      strokeWeight: 2
        });

  Track.setMap (map);
}

and then pass the values from delphi in this way

HTMLWindow2.execScript(Format('DrawTrack (%s,%s,%s,%s)',['-18.142599','178.431','-27.46758','153.027892']), 'JavaScript');

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.