How do I use AddPolyline method in Delphi

stephenmillington
09-10-2007, 05:10 AM
Can anyone give me some code that shows how to use the AddPolyline method to the shapes collection in Delphi. The number of points is dynamic. I have tried the following (VertexList just contains the list of points where each item is Latitude,Longitude

var
VertexList: TStringList;
LocationArray: array of variant;
begin
SetLength(LocationArray, VertexList.Count);
for i := 0 to VertexList.Count - 1 do
begin
LocationArray[i] := oMap.GetLocation(Piece(VertexList[i],',', 1), Piece(VertexList[i], ',', 2));
end;
oMap.Shapes.AddPolyline(VarArrayRef(LocationArray) );

This does actually draw the polyline but I get an access violation in oleaut32.dll. This seems to be when the procedure ends. I can only think this is something to do with the array being freed.

Wilfried
09-10-2007, 12:31 PM
Hi,

If it is because the array being freed you can try to put it as a private member in your class instead of on the stack frame as you do now. Please let us know if this works. If not then please post the complete procedure.

Oh yes and please put code into [ code ] tags. Then it shows up with the right indent and is much better to read :)

stephenmillington
09-18-2007, 03:54 PM
Hi

I tried moving the variable to a private member of my form but it made no difference which implied that wasn't the actual problem. I have now found a solution that works by making my LocationArray variable a variant and then using the VarArrayCreate function to create my array and then just passing my LocationArray variable to the AddPolyline method.

stephenmillington
09-18-2007, 04:33 PM
Hi

According to the help file in order to make the polyline closed you need to create an extra vertex which is the same as the first one which is fine. However, how do I know if freeform shapes drawn on the map are closed since the vertices property just contains the different points, i.e. when a polyline is closed it doesn't contain an extra vertex for the start point and there isn't a property that tells you if it is closed.

Stephen

Wilfried
09-20-2007, 12:52 PM
Hi,

I don't think you can see in the code if it is visually closed.

 
Web mp2kmag.com
mapforums.com