Locals: Var Parameters

Hi, Can anyone tell me what’s the use of the VAR field in the parameters tab of the locals screen in a function? I saw coding in a function that uses a parameter like a variable and the VAR field of the parameter was not checked and still it works. Regards Peter.

VAR means use pointer. If you passing to func. variable and it has been modified inside func, after func. call you get: 1. Modified variable if param is VAR 2. else Unmodified variable

Thanks for your reply. Do you mean calling another function with the VAR parameter from within the first function?

With var: ... A:=10; Func(A); MESSAGE('%1',A); // 0 ... Func(Var param1:Decimal) param1:=0 Without var: ... A:=10; Func(A); MESSAGE('%1',A); // 10 ... Func(param1:Decimal) param1:=0

VAR=No means Calling by Value. VAR=yes means Calling by reference. In first case (by value) you pass only value. Any cahnges of this parameter are not reflected outside the function. In second case (by ref) you pass a pointer to your var. It means you are actually dealing with (changing) your outside variable, it just has a different name in a function. This second way is more complex since if you don’t take a look inside a function, you don’t know if and how the var is changed. When calling by value, the outside var will never change. One more thing. Whwn calling a function with parm by value, you don’t have to specify a variable as parm. It can be also a constant: OpenFolderFile(‘Title od window’); or SetAmount(100); When calling by ref it must allway be a variable !

An important thing to keep in mind when passing a record variable as parameter to a function is that filters set on the record are only passed into the function when the VAR flag is set.

Heinz, you are right. Someone could foret this. This goes with “calling by value” - values of fields are passed, but nothing else.

Yup, I learned this the hard way [B)][:D]