Var, byref problem

First what I am used to (VB):

I create a function:

Function MyMethod(byRef x As String);
    x = "changed"
End Function

If I call this function - with whatever variable - can be a local, can be a property, can be anything, as long as it is the correct type:


And MyVar will have the value of “changed”

In Oxygene I find the following:

method MyMethod(var x: String);
    x := 'changed';

When I call it with:


I get an error.
I have to call it with

MyMethod(var myVar);
This is extra typing - not neccesary, because I already specified the “var” in the method.

And in Oxygene, this only works with local variables and field.

So, to get the 100% equivalent of the VB one-liner. I have to write in Oxygene:

var MyLocal := myVar;
MyMethod(var MyLocal);
myVar := MyLocal;

So 3 lines of code instead of 1 and an extra keyword in the middle call.
Can this be simplified to just one line of code without extra keywords?

This is as designed, sop that the nature of it being passed by reference is obvious at the call site. Was a conscious decision we made back in version 1.0 to deviate from Delphi there, and take C#'s suggestion.

It can’t work with a property, because a property can’t be passed by reference — access to it has to go thru the getter/setter, and it might not be a stored property, at all. You’ll need it as the three separate steps.

The var in the Caller should be added from Fire or water automatically
(It is a Setting somewhere , not on a pc to Check now) and a property is not a reference, so in my eyes it is correct

I am working with Visual Studio.

I know - I am just used to a compiler that does this work for me - saving me a lot of typing.

There should also be an option,
In vs i think.

But Pascal is not VB and there is a differente between the types

it’s highly misleading though. How is there actual property access handled? what if the called method updates the value several times, and the property has side effects?

@FritzW: I know.
But after 25 years of one language - and then switch to another, you want the best of both worlds.

1 Like

In the end we will become esparanto, and it was not a success i think🤓 but i understand your problem


I’m with you, when we’re talking actually best. Oxygene is very much an amalgamation of the best features and ideas from many languages (and some of our own). And I have no problems (and we probably already have) absorbing good features from VB, as well. But not every language feature that might seem convenient is necessarily good. This, IMHO, would be a bad “feature” – I’d almost call it a bug :wink: – to copy ;).


Ok, topic closed.

but, it is not a bug, it just implements the 2 extra lines automatically when needed.