Board index » delphi » PolyPolyLine/PolyPolygon functions

PolyPolyLine/PolyPolygon functions

Hi everybody,
I tried to use Windows API PolyPolyline and polypolygon functions in a
graphics routine to draw multi-segments or multipolygons at once but
couldn't use Delphi dynamic arrays. Here are the declarations and code
that I used:

var Points: array of TPoint;    //Points is read at run time from a file

     PolyPts: array of Integer;   //PolyPts holds the number of points
in each
                                               //    segment /polygon
   PolyCount: Integer;  //hold the number of segments/polygons to draw

After the arrays (i.e., Points, and PolyPts) are loaded with data at run
time I called:
PolyPolyLine(Canvas.Handle, Points, PolyPts, PolyCount);
PolyPolygon(Canvas.Handle, Points, PolyPts, PolyCount);
The code compiles with no error but after running nothing happens!!

When I changed the array declarations from dynamic to static like this:
var  Points: array[1..200] of TPoint;
      PolyPts: array[1..50] of Integer;

This time the code compiles and runs correctly and I have the lines and
polygons drawn.
So It seems to me that those Windows API functions can accept Delphi
dynamic arrays as parameters (because they compile) but don't draw
anything!!

Can anyone see where is the problem?
Is there any way to use these two functions but avoid the situation
where I have to use static arrays since I don't know at compile time how
many points will be loaded at run time?

Many thanks for any clarifications

 

Re:PolyPolyLine/PolyPolygon functions


Quote
abdellah EL-Idrysy <abdellah.elidr...@rug.ac.be> wrote:
>Hi everybody,
>I tried to use Windows API PolyPolyline and polypolygon functions in a
>graphics routine to draw multi-segments or multipolygons at once but
>couldn't use Delphi dynamic arrays.

Cast your dynamic arrays and deference them, like this:

PolyPolyLine(Canvas.Handle, Pointer(Points)^, Pointer(PolyPts)^, PolyCount);

Re:PolyPolyLine/PolyPolygon functions


Quote
"Ed Chafer" no wrote:
>Cast your dynamic arrays and deference them, like this:

>PolyPolyLine(Canvas.Handle, Pointer(Points)^, Pointer(PolyPts)^, PolyCount);

Another method is:

PolyPolyLine(Canvas.Handle, Points[0], PolyPts[0], PolyCount);

This style will work regardless of whether your arrays are dynamic or not.

Other Threads