Miscellaneous questions about converting VO code to X#

This forum is meant for questions and discussions about the X# language and tools
User avatar
robert
Posts: 4540
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by robert »

Kees,
The strange syntax in VO is for indexed assigns.
What is SELF:PKey in this context?

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Kees Bouw
Posts: 121
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

Robert,

Is it an array, defined like this:

Code: Select all

EXPORT PKey AS ARRAY
Kees.
User avatar
robert
Posts: 4540
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Kees Bouw
Posts: 121
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post 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.
User avatar
robert
Posts: 4540
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Chris
Posts: 4936
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Miscellaneous questions about converting VO code to X#

Post 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.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Kees Bouw
Posts: 121
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post 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.
User avatar
Chris
Posts: 4936
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Miscellaneous questions about converting VO code to X#

Post 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.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Kees Bouw
Posts: 121
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post 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.
User avatar
Chris
Posts: 4936
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Miscellaneous questions about converting VO code to X#

Post 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..
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply