xsharp.eu • Miscellaneous questions about converting VO code to X# - Page 3
Page 3 of 5

Re: Miscellaneous questions about converting VO code to X#

Posted: Fri Apr 19, 2024 1:56 pm
by robert
Kees,
The strange syntax in VO is for indexed assigns.
What is SELF:PKey in this context?

Robert

Re: Miscellaneous questions about converting VO code to X#

Posted: Fri Apr 19, 2024 2:08 pm
by Kees Bouw
Robert,

Is it an array, defined like this:

Code: Select all

EXPORT PKey AS ARRAY
Kees.

Re: Miscellaneous questions about converting VO code to X#

Posted: Fri Apr 19, 2024 2:14 pm
by robert
Kees,
I think that the code should be changed to:


SELF:PKey[nAUT] := #AUTNO

Most likely this was a bug in VO.

Robert

Re: Miscellaneous questions about converting VO code to X#

Posted: Fri Apr 19, 2024 2:15 pm
by Kees Bouw
Robert,

Well, you mentioned "assign" and I looked for it and indeed it is (also) an assign:

Code: Select all

ASSIGN PKey(KeyVal, NameSym) CLASS _BPDataDialog

LOCAL i AS DWORD

  IF Empty(SELF:FPKey)
    SELF:FPKey := {{NameSym, KeyVal}}      
  ELSE
    i := AScan(SELF:FPKey, {|aSub| aSub[1] = NameSym})
    IF i = 0 
      AAdd(SELF:FPKey, {NameSym, KeyVal})      
    ELSE
      SELF:FPKey[i,2] := KeyVal    
    ENDIF
  ENDIF

RETURN KeyVal   
I never heard of "indexed assigns". Is there an explanation somewhere that I can study?

Kees.

Re: Miscellaneous questions about converting VO code to X#

Posted: Fri Apr 19, 2024 2:19 pm
by robert
Kees,

You cannot have an EXPORT and ASSIGN with the same name.
If you rename the EXPORT then the syntax created by the Exporter should work.

Robert

Re: Miscellaneous questions about converting VO code to X#

Posted: Fri Apr 19, 2024 4:35 pm
by Chris
Hi Kees,

About indexed assigns or accesses:

Normally you have a regular ACCESS like that:

ACCESS MovieLength AS INT

that you can call with

nLength := oMovie:MovieLength

but it is also possible to have an access with an index part as a parameter ("nMoviePart" below), which can be used to supply more information to the ACCESS, to return different values based on it:

ACCESS MovieLength( nMoviePart AS INT ) AS INT

This is called an "indexed" property, that you can call with this X# syntax:

nLength := oMovie:MovieLength[2] // get length of 2nd part

Similarly for ASSIGNs, for declaring regular ones you just need to supply a single parameter that holds the new value:

ASSIGN MovieLength(nNewLength AS INT)
...
SELF:MovieLength := 100

and for indexed properties you need to supply also the "index":

ASSIGN MovieLength(nNewLength AS INT, nMoviePart AS INT)

and those can be called like that in X# syntax:

SELF:MovieLength[2] := 100 // set the length of part 2 to 100

Unfortunately, instead of this easy to read and use syntax for calling indexed assigns, VO uses this bizarre one:

SELF:[MovieLength , 2] := 100

Just because this is so strange, instead of this syntax, in X# we went for the more "normal" one above.

Re: Miscellaneous questions about converting VO code to X#

Posted: Fri Apr 19, 2024 7:56 pm
by Kees Bouw
robert wrote: Fri Apr 19, 2024 2:19 pm Kees,

You cannot have an EXPORT and ASSIGN with the same name.
If you rename the EXPORT then the syntax created by the Exporter should work.

Robert
I have renamed the export, and the syntax SELF:PKey[#AUTNO] seems to work. But, many times the class is inherited by another class and then the syntax is SELF:Owner:PKey[#AUTNO], where Owner is a USUAL. On those lines, I still get error XS9059 "Cannot convert Array Index from 'symbol' to 'int'".
Could it be that when the indexed access/assign is via a USUAL like Owner, you can't use Symbols?

Kees.

Re: Miscellaneous questions about converting VO code to X#

Posted: Fri Apr 19, 2024 9:02 pm
by Chris
Hi Kees,

Yes, calling indexed properties is not supported (yet, at least) through late bound calls. You will ned to use an intermediate typed variable for that, like:

LOCAL oOwner AS ClassNameOfOwner
oOwner := (ClassNameOfOwner) SELF:Owner
oOwner:PKey[#AUTNO] := ...

where you will need to replace "ClassNameOfOwner" with the actual class name of course.

Re: Miscellaneous questions about converting VO code to X#

Posted: Mon Apr 22, 2024 8:21 am
by Kees Bouw
Chris,

Thank you for the explanation and also for the previous explanation! The problem exists in at least 137 locations (if I import more code, the number will go up) in the application so it will be a lot of work to modify them all to the workaround but I guess there is no other way...

Kees.

Re: Miscellaneous questions about converting VO code to X#

Posted: Mon Apr 22, 2024 8:44 am
by Chris
Hi Kees,

If it helps, it can also be done without an intermediate variable, but in a single line, it's just less readable:

( (ClassNameOfOwner) SELF:Owner):PKey[#AUTNO] := ...

You will still need to supply the class name, but if it's the same in most cases, then a global search & replace might make things much easier..