Kompatibilität VO vs. X#

Deutschsprachiges X#-Forum – German language forum

Moderator: wriedmann

Post Reply
lagraf
Posts: 523
Joined: Thu Jan 18, 2018 9:03 am
Location: A

Kompatibilität VO vs. X#

Post by lagraf »

Hallo,
ich stelle grad ein VO Prog auf X# um. Dabei ist mir folgende Konstellation untergekommen:

In VO

Code: Select all

Aufruf einer Funktion
oDCtxtKunde:Caption := GetKndText(@nKndid, @nKarte, @nRabatt, @cBemerk, @nUmsGes)
oDCtxtKunde:Caption := GetKndText(@nKndid)
Definition der Funktion
FUNCTION GetKndText(nKndid, nKarte := 0, nRabatt := 0, cBemerk := "", nUmsGes := 0) AS STRING PASCAL
In X# bekomme ich error XS9109: Argument x may not be passed with the '@' prefix, ich muss daher umbauen

Code: Select all

FUNCTION GetKndText(nKndid REF DWORD, nKarte := 0 REF DWORD, nRabatt := 0 REF FLOAT, cBemerk := "" REF STRING, nUmsGes := 0 REF FLOAT) AS STRING PASCAL
Dieses Typing funktioniert zwar auch in VO, aber wenn ich in VO einen Aufruf mache ohne alle Parameter anzugeben

Code: Select all

oDCtxtKunde:Caption := GetKndText(@nKndid)
bekomme ich den Fehler type conflict in reference operation.

Gibt es eine Variante, die für die beiden Aufrufe in beiden Umgebungen funktioniert?

LG
User avatar
Chris
Posts: 5585
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Kompatibilität VO vs. X#

Post by Chris »

Hi Franz,

In VO the "@" operator is used for both "pass var by reference" and for "Address of", which are different things in .Net.

The proper way to do this in .Net/X#, is to use the REF keyword instead of "@", to let the compiler know that you are passing a var by reference.

You can also enable the compiler option /vo7 (compatible implicit casts and conversions) to tell the compiler to do this under the hood. But that will not work for the Core dialect, so if your app uses this, then please just replace "@" with "REF"
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
lagraf
Posts: 523
Joined: Thu Jan 18, 2018 9:03 am
Location: A

Re: Kompatibilität VO vs. X#

Post by lagraf »

Hi Chris and thank you for answer!
I'm using VO Dialect do I can use /vo7 for better compatibility between VO and X#
Regards
lagraf
Posts: 523
Joined: Thu Jan 18, 2018 9:03 am
Location: A

Re: Kompatibilität VO vs. X#

Post by lagraf »

Hi Chris,
I tried to set /vo7 but it's already checked!
if I then compile the following code from VO

Code: Select all

Aufruf der Funktion
oDCtxtKunde:Caption := GetKndText(@nKndid, @nKarte, @nRabatt, @cBemerk, @nUmsGes)
oDCtxtKunde:Caption := GetKndText(@nKndid)
Definition der Funktion
FUNCTION GetKndText(nKndid, nKarte := 0, nRabatt := 0, cBemerk := "", nUmsGes := 0) AS STRING PASCAL
I get error error XS9109: Argument 1 may not be passed with the '@' prefix.

My intention is to use same code in VO and X# to simply transfer new features made in VO by transporting source to X# with less manual intervention.

Regards
User avatar
wriedmann
Posts: 4059
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Kompatibilität VO vs. X#

Post by wriedmann »

Hi Franz,
if you have to share code between X# and VO,

Code: Select all

#ifdef __XSHARP__
is your friend.

Code: Select all

#ifdef __XSHARP__
// X#-Version of code
#else
// VO-Version of code
#endif
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 5585
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Kompatibilität VO vs. X#

Post by Chris »

Hi Franz,

Ah, OK, I thought you wanted to use the REF syntax. In .Net, you cannot have strongly typed functions, have parameters typed without REF and then call them with arguments by reference. You have to indicate that the parameters need to be passed by reference:

Code: Select all

FUNCTION GetKndText(nKndid REF INT, nKarte := 0 REF INT, nRabatt := 0 REF INT, cBemerk := "" REF STRING, nUmsGes := 0 REF INT) AS STRING PASCAL
This works in X#, but I see calling this function and omitting arguments does not work in VO, so you can't have the exact same code in both. But maybe the other parameters (except for nKndid) do not really need to be passed by reference? Can you post the complete code of the function to have a look?
Chris Pyrgas

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