Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

value in USUAL does not support indexed operations 13 Mar 2023 14:46 #25611

  • ic2
  • ic2's Avatar
  • Topic Author


  • Posts: 1662
  • We get a return value from a C# based 3rd party DLL which looks as follows when we inspect (tooltip) the usual uTot:
    uTot System.String[,] (String[,]
    [0,0] "NL"
    [0,1] "7543"

    (etc)

    How can we access this in X#?

    If we try it like with something like uSomething:= uTot[0,0] we get the error below:


    'uTot[0,0]' threw an exception of type 'System.InvalidCastException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2147467262
    HelpLink: null
    InnerException: null
    Message: "value in USUAL does not support indexed operations. The value needs to be an X# Array or implement the interface 'XSharp.IIndexedProperties'."
    Source: "XSharp.RT"
    StackTrace: " at XSharp.__Usual.get_Item(Int32 index1, Int32 index2)"
    TargetSite: {XSharp.__Usual get_Item(Int32, Int32)}


    Dick

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

    value in USUAL does not support indexed operations 13 Mar 2023 15:56 #25615

    • robert
    • robert's Avatar


  • Posts: 3588
  • Dick,
    Most likely, you have stored the return value of the C# call in an untyped variable (a USUAL)
    Do you know what the C# call returns?
    Please use that type for uTot, or else declare uTot with VAR:

    var uTot := externalObject:MethodName()

    The compiler will then query the object and retrieve its return type.

    Robert
    XSharp Development Team
    The Netherlands

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

    value in USUAL does not support indexed operations 13 Mar 2023 16:36 #25616

    • ic2
    • ic2's Avatar
    • Topic Author


  • Posts: 1662
  • Hello Robert,

    We already saw it was a string array when hovering on uTot:
    uTot System.String[,] (String[,]

    But we can't access it like we tried, with e.g. something like ? uTot[0,0] which has the value "NL" (also seen hovering)

    Dick

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

    value in USUAL does not support indexed operations 13 Mar 2023 17:31 #25617

    • Chris
    • Chris's Avatar


  • Posts: 3975
  • Hi Dick,

    Declare "uTot AS STRING[,]", does it work now?

    (btw, that's an array, not an indexed expression)
    XSharp Development Team
    chris(at)xsharp.eu

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

    Last edit: by Chris.

    value in USUAL does not support indexed operations 14 Mar 2023 12:23 #25623

    • ic2
    • ic2's Avatar
    • Topic Author


  • Posts: 1662
  • Hello Chris,

    That works indeed, thanks.

    One question: what is the difference with some of the other datatypes?

    E.g. if I would define ux as usual and the value assigned is a normal string,
    ? ux
    would work without crash (where it doesn't for this string[,] datatype) and e.g.
    nMyIntVar:=ux+5

    would fail as expected.

    Dick

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

    Last edit: by ic2.

    value in USUAL does not support indexed operations 14 Mar 2023 12:53 #25624

    • Chris
    • Chris's Avatar


  • Posts: 3975
  • Hi Dick,

    Not sure if I understand what you mean, but assigning a strongly typed array to a usual it is indeed possible:

    LOCAL a AS STRING[]
    a := STRING[]{10}
    
    LOCAL u AS USUAL
    u := a

    But it's just not really useful doing that.
    XSharp Development Team
    chris(at)xsharp.eu

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

    value in USUAL does not support indexed operations 14 Mar 2023 22:03 #25632

    • ic2
    • ic2's Avatar
    • Topic Author


  • Posts: 1662
  • Hello Chris,

    What I mean is this. Trying to get a value from the usual (although visible in VS' debugger tooltip) like uSomething:= uTot[0,0] we get the error as described earlier.

    But if would use cSomething:=uSomething (where the first is a string and the 2nd a usual) would work (if the actual value of the usual is a string) , I think?

    Dick

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

    value in USUAL does not support indexed operations 14 Mar 2023 22:12 #25633

    • robert
    • robert's Avatar


  • Posts: 3588
  • Dick,
    We have implemented the USUAL type very close to what exists inside VO.
    And typed arrays like STRING[] did not exist in VO.

    In theory, we could extend the USUAL type and add an indexer to that type. And then we could detect that the object inside the USUAL is a STRING[] or something similar, and then translate uValue[10] into retrieving the 10th element from the string array.

    In fact, we already have an indexer for the USUAL type, but this indexes (like in VO) assumes that it should only work for usuals that contain an Xbase array. We did not think that would be necessary to support typed arrays, but it is not super difficult to do that.

    Robert
    XSharp Development Team
    The Netherlands

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

    value in USUAL does not support indexed operations 14 Mar 2023 23:30 #25634

    • Chris
    • Chris's Avatar


  • Posts: 3975
  • Robert,

    In VO, when you store a DIM array (which is close enough to .Net's arrays) in a USUAL, it is not possible to access element arrays with it. This code in VO:

    FUNCTION Start() AS INT
    LOCAL DIM aaa[10] AS INT
    LOCAL u AS USUAL
    aaa[2] := 123
    ? aaa[2] // 123
    
    u := aaa
    ? u[2] // Data Type error

    produces a Data Type Error at runtime, so in order to maintain VO compatibility, I think also in X# it should continue throwing a runtime error, too.
    XSharp Development Team
    chris(at)xsharp.eu

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

    value in USUAL does not support indexed operations 15 Mar 2023 11:11 #25636

    • ic2
    • ic2's Avatar
    • Topic Author


  • Posts: 1662
  • Hello Robert, Chris,

    Thanks for explaining. It is not that I needed the behaviour to change, I was just curious why accessing usuals with e.g. a string worked. Now I know the background and also how it won't work with normal VO arrays either.

    Dick

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

    value in USUAL does not support indexed operations 15 Mar 2023 13:04 #25637

    • Chris
    • Chris's Avatar


  • Posts: 3975
  • Hi Dick,

    With normal (as in regular, untyped ragged arrays, the ones you create with ArrayCreate() or a := {1,2,3}) arrays, it does work, because it was working in VO, too. What doesn't work, is with strongly typed arrays, since this wasn't supported in VO, either.
    XSharp Development Team
    chris(at)xsharp.eu

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

    • Page:
    • 1