Dec 102017
 
Clipper '87 array handling information.
File ARRAYINF.ZIP from The Programmer’s Corner in
Category Dbase Source Code
Clipper ’87 array handling information.
File Name File Size Zip Size Zip Type
ARRAYINF.DOC 4839 1864 deflated

Download File ARRAYINF.ZIP Here

Contents of the ARRAYINF.DOC file


TO: Clipper programmers

FROM: Dirk Lesko
dLESKO ASSOCIATES


A little note to all you Clipper developers who have been trying to
access Clipper arrays in your 'C' and assembler UDF's. I would suggest
a strong phone call to Nantucket emphasizing the importance of documenting
the features of the compiler so that we as developers can get the most
power out of it. I say this because it appears that we all have had the
capability to access arrays and array elements in our UDF's ever since
we have had the Autumn86 version of Clipper.

I have read much info from programmers who have spent hours upon hours
trying to access array elements, and I myself have spent much time on
the same issue. It seems however that we all took the wrong approach.
Access to arrays has been available all the time, we just overlooked it.
If you would look at the extendc.h header file, you will notice a reference
to an internal Clipper routine called _parinfa(). _parinfa() can be used to
return the length of the array passed. It can also be used to get the type
of array element (character, data, integer etc.) by passing the element
number you are interested in. The type of the element is returned the
same as for the _parinfo() function. for those wishing to use parinfa, the
format for the call is:

'C':


type = _parinfa(parameter,element) /* just like _parinfo */


Assembler:


mov ax, element
push ax

mov ax, parameter
push ax

call _parinfa ; result in ax like _parinfo
add sp, 4


Now, the parameter is the # of the parameter as it actually appears in the
function list, and element is the element # inside the array you want
to access. Your return value will be the same as for _parinfo. Character = 1,
numeric = 2, logical = 4, date = 8, etc. In assembler this value will be
returned in ax. If you wanted to find the length of the array, you simply
pass a 0 as the element number, and the length will be returned in ax for
assembly, or as an integer in 'C'. Be careful that the element number is
definitely in the array. Clipper hangs on element numbers that are not
within the array. If your return value is 0, then that element is not
defined.

Now, this seems simple enough, and I believe that most 'C' and assembly
programmers have gotten this far. However, no mention of any kind is given
to how to get at the elements!! - and this is where Nantucket should have
been more open. How many powerful UDF's did not get written because no one
knew how to access arrays? Hasn't this helped to stifle Clipper as a serious
development tool? You know the answers to these questions.

Now, the amazing part is that we have had access to all the elements all
along. The way to get at them is simple, and could have been documented
in a simple read.me file (yes another one). I know you will hit yourself
when I tell you......

To access an array element in your 'C' or assembler UDF requires that you
send TWO parameters to the _parc() _parni() _pards() _parnl() _parl()
and _parnd() functions!! simple!! Why didn;t they tell us!!!!!

To access an array element as a string, all you need to do is this:


'C':

str = _parc(parameter, element)


Assembler:


mov ax, element
push ax

mov ax, parameter
push ax

call _parc ; ax:bx will point to the string
add sp, 4


To access an array element as an integer, all you need to do is this:


'C':

int = _parni(parameter, element)


Assembler:


mov ax, element
push ax

mov ax, parameter
push ax

call _parni ; ax will contain the integer
add sp, 4


parameter is the number of the parameters as it actually appears in the
function list - this parameter must be the name of the array you are
passing. And element is the element number of the array you want to
access. All we needed to do in assembler was push the array element number
on the stack first, gosh, I could've had a V-8!! how simple could it have
been!

Now, you can see how simple this is because it is virtually identical
to accessing any other parameter, and you already know how to do that.
You can modify your mac file so that you can access array elements very
easily. The thing that gets me though is that this was here all the time!!!

If you have any comments, or additional information. I can be contacted
at dLESKO ASSOCIATES, PO Box 3382, Jersey City, NJ, 07303-3382. Or you
can find me on the BOSS BBS at (201)568-7293.


I hope you find this information enlightening.



Yours truly,



Dirk Lesko
dLESKO ASSOCIATES


 December 10, 2017  Add comments

Leave a Reply