copy/convert between fox array and xsharp array
- kevclark64
- Posts: 127
- Joined: Thu Aug 15, 2019 7:30 pm
- Location: USA
copy/convert between fox array and xsharp array
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
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:
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:
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
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
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}
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
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
- kevclark64
- Posts: 127
- Joined: Thu Aug 15, 2019 7:30 pm
- Location: USA
copy/convert between fox array and xsharp array
Thanks, Robert, that's very helpful.