Bo Berglund via fpc-pascal <fpc-pascal@lists.freepascal.org> schrieb am
Mi., 12. Apr. 2023, 21:17:

> Now my question:
> ----------------
> Since I am modifying the WArgs variable inside the BuildArgumentsArray
> function
> and using its new content afterwards in the WriteItem function I assumed
> that I
> had to use var as shown above, but I am not certain this is the case...
>

If you modify the length or the contents of a dynamic array parameter then
you need to use "var" or "out" modifiers (the later only if you don't need
the data passed in).


> It seems like it works also if I do not use the vars specification...
>

It should not. If it does it will likely be an implementation detail and
you shall not rely on it. Do you have an explicit example for this
behavior?

And if so, what is the rule for *when* to use var in function call argument
> lists for items that will be changed inside the called function and used
> afterwards
>

The rule is simple: if you need to modify the parameter value itself (e.g.
changing a primitive type, changing a field in a record, changing an
array's length or data, changing the value of a class instance - but not
its fields!) you need to pass it as "var". If it's a write only parameter
you can even use "out".

Regards,
Sven

>
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to