I am getting the error message below when exiting my program if I have more than one Polyline on the map.
"Project utilmarker.exe raised exception class EInvalidPointer with message 'Invalid pointer operation'.
I went back to the basics from your sample code and came up with this to show my problem using only 2 Polylines...
procedure TMainForm.AddPolylinesToMap;
var
Icons: TSymbols;
pi: TPathItem;
aPath: TPath;
begin
Icons := TSymbols.Create;
aPath := TPath.Create;
pi := aPath.add;
pi.Latitude := 39.58108;
pi.Longitude := -105.63535;
pi := aPath.add;
pi.Latitude := 40.315939;
pi.Longitude := -105.440630;
pi := aPath.add;
pi.Latitude := 43.785890;
pi.Longitude := -101.90175;
MyMap.Polylines.Add(True, False, False, Icons, aPath, clBlue, 100, 10, True, 0);
aPath.Clear;
pi := aPath.add;
pi.Latitude := 49.58108;
pi.Longitude := -115.63535;
pi := aPath.add;
pi.Latitude := 50.315939;
pi.Longitude := -115.440630;
pi := aPath.add;
pi.Latitude := 53.785890;
pi.Longitude := -111.90175;
MyMap.Polylines.Add(True, False, False, Icons, aPath, clBlue, 100, 10, True, 0);
end;
For testing purposes trying to find what is causing my problem I have did these tests
1) call MyMap.Polylines.Clear before adding the second Polyline, when I exit I do not get the error (has something to do with reusing the variables icons or apath?)
2) create a second set of variables (Icons2, pi2 and aPath2). Substitute those variables for the second Polyline and I do not get the error.
Second Polyline would be
MyMap.Polylines.Add(True, False, False, Icons2, aPath2, clBlue, 100, 10, True, 0); (no error on exit)
3) if I re-use either Icons or aPath variables in the second Polyline I get the error:
MyMap.Polylines.Add(True, False, False, Icons, aPath2, clBlue, 100, 10, True, 0); (error on exit)
or
MyMap.Polylines.Add(True, False, False, Icons2, aPath, clBlue, 100, 10, True, 0); (error on exit)
What am I doing wrong to programmatically add multiple Polylines at runtime?
Hi,
Can you please try to do a create instead of a clear on the Path and Icons?
Example:
procedure TMainForm.AddPolylinesToMap;
var
Icons: TSymbols;
pi: TPathItem;
aPath: TPath;
begin
Icons := TSymbols.Create;
aPath := TPath.Create;
pi := aPath.add;
pi.Latitude := 39.58108;
pi.Longitude := -105.63535;
pi := aPath.add;
pi.Latitude := 40.315939;
pi.Longitude := -105.440630;
pi := aPath.add;
pi.Latitude := 43.785890;
pi.Longitude := -101.90175;
MyMap.Polylines.Add(True, False, False, Icons, aPath, clBlue, 100, 10, True, 0);
//aPath.Clear;
var
Icons: TSymbols;
pi: TPathItem;
aPath: TPath;
begin
Icons := TSymbols.Create;
aPath := TPath.Create;
pi := aPath.add;
pi.Latitude := 39.58108;
pi.Longitude := -105.63535;
pi := aPath.add;
pi.Latitude := 40.315939;
pi.Longitude := -105.440630;
pi := aPath.add;
pi.Latitude := 43.785890;
pi.Longitude := -101.90175;
MyMap.Polylines.Add(True, False, False, Icons, aPath, clBlue, 100, 10, True, 0);
//aPath.Clear;
aPath := TPath.Create;
Icons := TSymbols.Create;
pi := aPath.add;
pi.Latitude := 49.58108;
pi.Longitude := -115.63535;
pi := aPath.add;
pi.Latitude := 50.315939;
pi.Longitude := -115.440630;
pi := aPath.add;
pi.Latitude := 53.785890;
pi.Longitude := -111.90175;
MyMap.Polylines.Add(True, False, False, Icons, aPath, clBlue, 100, 10, True, 0);
end;
pi := aPath.add;
pi.Latitude := 49.58108;
pi.Longitude := -115.63535;
pi := aPath.add;
pi.Latitude := 50.315939;
pi.Longitude := -115.440630;
pi := aPath.add;
pi.Latitude := 53.785890;
pi.Longitude := -111.90175;
MyMap.Polylines.Add(True, False, False, Icons, aPath, clBlue, 100, 10, True, 0);
end;
That solved my problem! I had previously tried doing creates on them for each Polyline iteration in my original code but apparently I had mistakenly placed them in the wrong place in my loop. Thanks!!!