J'utilise un TWebbrowser dans mon appli Delphi 10 pour y afficher une carte du monde puis le tracé d'un vol.

J'ai bien OleCtrls, SHDocVw, et MSHTML dans les uses

La déclaration de HTMLWindow est :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
...
private
    { Déclarations privées }
    HTMLWindow2: IHTMLWindow2;
...
Le script Java est:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 
HTMLStr: AnsiString = //Java scrip for Google map
'<html> '+
'<head> '+
'<meta name="viewport" content="initial-scale=1.0, user-scalable=yes" /> '+
'<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3&sensor=true"></script> '+   //24/2/2015
'<script type="text/javascript"> '+
'  var map;'+
'  var polyline = [];'+
'  var markersArray = [];'+
'  var Circle = { '+
'  path: google.maps.SymbolPath.CIRCLE ,'+
'  fillColor: "Red",'+
'  fillOpacity: 1.0,'+
'  scale: 3,'+
'  strokeColor:"Black",'+
'  strokeWeight: 1 '+
'};'+
''+
''+
'  function initialize() {'+
'  var myLatLng = new google.maps.LatLng(48.0,2.0);'+
'  var mapOptions = {'+
'    zoom: 5,'+
'    center: myLatLng,'+
'    mapTypeId: google.maps.MapTypeId.TERRAIN'+
'  };'+
'  map = new google.maps.Map(document.getElementById("map_canvas"),'+
'      mapOptions);'+
'}'+
''+
' 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'+
' });'+
' polyline.push(Track);'+
' Track.setMap (map);'+
'}'+
''+
''+
' function RemoveTrack(){' +
'  if (polyline){' +
'    for(i in polyline){' +
'      polyline[i].setMap(null);' +
'    }' +
'     polyline.length =0;' +
'   }' +
'}' +
''+
'function ClearMarkers() {  '+
'  if (markersArray) {        '+
'    for (i in markersArray) {  '+
'      markersArray[i].setMap(null); '+
'    } '+
'  } '+
' Bounds = new google.maps.LatLngBounds();'+
'}  '+
''+
'var Bounds = new google.maps.LatLngBounds(); '+
'  function PutMarker(Lat, Lang, Msg) { '+
'   var latlng = new google.maps.LatLng(Lat,Lang);'+
'   var marker = new google.maps.Marker({'+
'      position: latlng,'+
'      icon: Circle,'+
'      map: map,'+
'      title: Msg'+
'  });'+
' markersArray.push(marker); '+
' Bounds.extend(latlng);'+
' map.fitBounds(Bounds);'+
'}'+
''+
''+
''+'</script> '+
'</head> '+
'<body onload="initialize()"> '+
'  <div id="map_canvas" style="width:100%; height:100%"></div> '+
'</body> '+
'</html> ';
La procedure Form Create est:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
procedure TfrmBrowser.FormCreate(Sender: TObject);
var
   aStream : TMemoryStream;
begin
  if Assigned(wbrWxCharts.Document) then
  begin
    aStream:= TMemoryStream.Create;
    try
      aStream.WriteBuffer(Pointer(HTMLStr)^, Length(HTMLStr));
      aStream.Seek(0, soFromBeginning);
      (wbrWxCharts.Document as IPersistStreamInit).Load(TStreamAdapter.
                                                        Create(aStream));
    finally
      aStream.Free;
    end;
    HTMLWindow2 := (wbrWxCharts.Document as IHTMLDocument2).parentWindow;
  end;
end;
La procedure FormActivate est:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
procedure TfrmBrowser.FormActivate(Sender: TObject);
begin
  if frmTripPlanner.btnFlightMap.Tag = 1 then
  begin
    HTMLWindow2.execScript(Format('RemoveTrack()',[]),'JavaScript');     
    HTMLWindow2.execScript(Format('ClearMarkers()',[]),'JavaScript');       
    HTMLWindow2.execScript('initialize()','JavaScript');
    PlotMap;
    frmTripPlanner.btnFlightMap.Tag:= 0;
  end;
end;
Lors de l'ouverture de la fiche, j'ai une violation d'accès sur la ligne:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
HTMLWindow2.execScript(Format('RemoveTrack()',[]),'JavaScript');
Pourriez vous m'aider à résoudre ce problème.

Cordialement
Pierre