Calling a class that has no public constructor
Posted: Wed Feb 22, 2017 5:35 pm
Hi Jean-Pierre,
Ahh, I love seeing c# code, it is so clear to read...
Well, this method declaration in the c# code:
public void FromVegas(Vegas vegas)
defines the FromVegas() method with one parameter, named vegas and its type is Vegas (I know...). The equivalent VO/x# definition would be:
METHOD FromVegas(vegas AS Vegas) AS VOID
So the c# code MessageBox.Show(vegas.Version) operates on the "vegas" local (parameter), not on the "Vegas" (with capital V) type itself. In VO/x# syntax again, this would be:
MessageBox.Show(vegas:Version)
so this should compile fine in x:
METHOD FromVegas(vegas AS Vegas) AS VOID
MessageBox.Show(vegas:Version)
or I would suggest to change the parameter name to something else, so it is more clear what the code does, something like (for example):
METHOD FromVegas(oVegas AS Vegas) AS VOID
MessageBox.Show(oVegas:Version)
the reason why you get a compiler error in this code:
FUNCTION start() AS VOID
MessageBox.Show(vegas:version)
is that there is no variable named "vegas" defined in this function, so the compiler thinks that you are attempting to call a static method on the same named "Vegas" class itself. If you had defined a "LOCAL vegas AS Vegas", then it would again compile fine, but would obviously fail at runtime, because "vegas" (the var...) would be NULL.
Chris
Ahh, I love seeing c# code, it is so clear to read...
Well, this method declaration in the c# code:
public void FromVegas(Vegas vegas)
defines the FromVegas() method with one parameter, named vegas and its type is Vegas (I know...). The equivalent VO/x# definition would be:
METHOD FromVegas(vegas AS Vegas) AS VOID
So the c# code MessageBox.Show(vegas.Version) operates on the "vegas" local (parameter), not on the "Vegas" (with capital V) type itself. In VO/x# syntax again, this would be:
MessageBox.Show(vegas:Version)
so this should compile fine in x:
METHOD FromVegas(vegas AS Vegas) AS VOID
MessageBox.Show(vegas:Version)
or I would suggest to change the parameter name to something else, so it is more clear what the code does, something like (for example):
METHOD FromVegas(oVegas AS Vegas) AS VOID
MessageBox.Show(oVegas:Version)
the reason why you get a compiler error in this code:
FUNCTION start() AS VOID
MessageBox.Show(vegas:version)
is that there is no variable named "vegas" defined in this function, so the compiler thinks that you are attempting to call a static method on the same named "Vegas" class itself. If you had defined a "LOCAL vegas AS Vegas", then it would again compile fine, but would obviously fail at runtime, because "vegas" (the var...) would be NULL.
Chris