xsharp.eu • copy/convert between fox array and xsharp array
Page 1 of 1

copy/convert between fox array and xsharp array

Posted: Thu Jun 30, 2022 7:52 pm
by kevclark64
Is there an easy way to either convert a fox array to an xsharp array (and vice versa) while keeping the contents, or to copy the contents of one type of array to the other type of array?

copy/convert between fox array and xsharp array

Posted: Fri Jul 01, 2022 9:55 am
by robert
Kevin,
Single dimensional or multi dimensional foxpro array ?
Internally foxpro arrays are derived from the 'generic' array type, and are implemented as a single dimensional array.
Multiple dimensions are achieved by calculating the offset from the row/column specified.
That is why you can also access them with a single index (like in FoxPro).
What you can do is something like this:

Code: Select all

FUNCTION Start() AS VOID
PUBLIC ARRAY aFoxArray(3)
aFoxArray := 42 // fill the array with 42
LOCAL aArray as ARRAY
aArray := aFoxArray
ShowArray(aFoxArray)
ShowArray(aArray)
WAIT
RETURN
The array is still a fox array but recognized as array by the runtime.
However some operations will still not be possible. For example you can't assign a subarray.
To "truely" convert you will need to do something like this:

Code: Select all

LOCAL aArray as ARRAY
aArray := Array{ (ARRAY) aFoxArray}
This will create a new array and will add all elements of the FoxPro array to it.
You can see the difference, since the ShowArray() function will use parentheses for FoxPro arrays and will use square brackets for 'normal' arrays.

You will have to add the ARRAY cast because the PUBLIC array is not really typed (like in FoxPro) so the compiler does not know which constructor of the array class to call.
Of course this also works with LOCAL ARRAY (which create a local array) or with DIMENSION (which creates a private array)

If you declare the array with 2 dimensions (like in PUBLIC ARRAY aFoxArray(2,3) )
then the resulting array will have a single dimension with all of the elements of the FoxPro array duplicated.

Robert

copy/convert between fox array and xsharp array

Posted: Fri Jul 01, 2022 12:55 pm
by kevclark64
Thanks, Robert, that's very helpful.