Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

copy/convert between fox array and xsharp array 30 Jun 2022 21:52 #22932

  • kevclark64
  • kevclark64's Avatar
  • Topic Author


  • Posts: 126
  • 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?

    Please Log in or Create an account to join the conversation.

    copy/convert between fox array and xsharp array 01 Jul 2022 11:55 #22936

    • robert
    • robert's Avatar


  • Posts: 3600
  • 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:
    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:
    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
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    copy/convert between fox array and xsharp array 01 Jul 2022 14:55 #22938

    • kevclark64
    • kevclark64's Avatar
    • Topic Author


  • Posts: 126
  • Thanks, Robert, that's very helpful.

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1