[Shapelib] Problems using SHPDestroyObject()

Brian Peschel brianp at occinc.com
Mon Nov 22 09:31:19 PST 2010


> Hi all,
> I am trying to write an intersection-tool with Delphi using ShapeLib 1.2.10.
> Everything works proper with small shapes but when I try to intersect bigger
> shapes, after some time an access-violation message occurs when I try to
> read a shape using the SHPReadObject()-method.
> Possibly the problem is that I am not using SHPDestroyObject(). It causes an
> error-message the first time I access it.
>
> The following code works fine:
>        pSHPStr := SHPReadObject(hSHPHandleStr,i);
>        SHPDestroyObject(pSHPStr);
>
> This code causes an cpu-error-message in my Delphi IDE:
>        pSHPStr := SHPReadObject(hSHPHandleStr,i);
>        aXIn := pSHPStr.padfX; //Array of nVertices X coordinates;
>        aYIn := pSHPStr.padfY; //Array of nVertices Y coordinates;
>        SHPDestroyObject(pSHPStr);
>
> Do you have any ideas what the problem could be? Thanks a lot!
> Mario H?
padfX and padFY are pointers into the pSHPStr object.  Once you call 
SHPDestroyObject(), aXIn and aYIn are no longer valid.  Instead you want 
to do something like

for (int i = 0; i < size, i++
{
     pSHPStr := SHPReadObject(hSHPHandleStr,i);
     aXIn := pSHPStr.padfX; //Array of nVertices X coordinates;
     aYIn := pSHPStr.padfY; //Array of nVertices Y coordinates; < use 
aXIn, aYIn >
     SHPDestroyObject(pSHPStr);
}

- Brian



More information about the Shapelib mailing list