Cancel
Showing results for 
Search instead for 
Did you mean: 

[DISCUSSION] Passing global variables by reference(byref)

Legend
Legend

Hello!

 

As the Help Topic for byref clearly states, that we can only pass local variables with the expression byref, I was wondering why this is the case.

 

When you only have 1 relevant global variable, it is not a serious problem. However, when working with a lot of variables it becomes rather difficult to handle them. 

Any ideas or suggestions?

 

Sanchay

5 REPLIES

Re: [DISCUSSION] Passing global variables by reference(byref)

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

the global variable itself is an object and objects are passed by default as reference, so only for primitive data-types it is necessary to differ between copy the value or pass a reference, so that you can access the variable itself

Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net

Re: [DISCUSSION] Passing global variables by reference(byref)

Legend
Legend

But even when a global variable is  simply passed(without byref) as a parmeter to a method, apparently the method still creates a copy of the variable.

It would not be possible to change the value of the passed variable from the method unless we explicitly do it using the absolute path of the variable. 

Re: [DISCUSSION] Passing global variables by reference(byref)

Legend
Legend

global var.PNGSomething like this

Re: [DISCUSSION] Passing global variables by reference(byref)

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

not completely

 

if you want to pass the variable itself, you need to define the parameter as object

 

param var1: object

 

to pass the variable:

 

print byrefTest(&variable)

Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net

Re: [DISCUSSION] Passing global variables by reference(byref)

Legend
Legend

Oh! this clears it up. In this case, the value can then be accessed/assigned by writing

 

var1.Value

 

Thus, the behaviour similar to a 'byref' will be preserved.

Thanks!