Page 1 of 1

Arrays : an important difference in DCAL for Delphi

PostPosted: Thu Aug 03, 2017 10:30 am
by dhs
I recently posted the source code to my PntInPly function and stated that it was based on a Classic DCAL function that had had quite a lot of testing. Whilst that was true, the translation to DCAL had introduced a bug for the following reason:

Arrays in Classic DCAL are indexed starting at 1 by default
Arrays in Delphi are indexed starting at 0 by default

Whilst the predefined array types are defined with 1 as the low index (e.g. pntarr is defined as array[1 .. maxpoly]), if you have used open arrays in your DCAL code then you need to be aware of the difference if you bring your code over to Delphi.
In my DCAL PntInPly function I had simply defined the parameter as 'Array of Point'. This allowed me to pass an array of any size as the parameter and I did this because I wanted to allow it to process larger arrays as well as the predefined pntarr type (which in Classic DCAL on ly has 36 elements). The requirement for arrays larger then pntarr is not nearly as important in D4D as maxpoly is now 256, but none-the-less I brought the existing open array definition over into my Delphi code. But I did not update the processing within the procedure.
The result of this is the the procedure I posted has a bug because the parameter passed is a zero based array, but I treat it as though it has a lower bound of 1. Easity fixed by either changing the parameter to pntarr or changing the logic to start the processing loop at 0 instead of 1.