[Gambas-user] ByRef

gambas at ...1938... gambas at ...1938...
Tue Sep 2 18:04:16 CEST 2008


Am Dienstag, 2. September 2008 16:35:47 schrieb Benoit Minisini:
>
> The ByRef feature was mainly added to help people porting VB project.
>
> It does not work by passing pointers, but by keeping the value of the
> argument when the function ends, and put it into the expression passed
> ByRef.
>
>   GetData(ByRef sResult)
>
> does actually the following:
>
>   GetData(sResult) ' Push sResult on the stack as first argument.
>   ...              ' Do not free the stack after GetData ends.
>   sResult = ...    ' Gets the value from the stack and put it into sResult.
>
> Note that this way, any assignment expression can be passed by reference.
>
>   GetData(ByRef MyCollectionOfLabels["key"].Text)
>
> At function declaration, ByRef means that you *can* pass the argument by
> reference, but that you may not.
>
> At function call, ByRef means that you *want* the argument to be passe by
> reference.
>
> As Gambas linking is entirely dynamic, the interpreter checks at runtime
> that you use ByRef if the function really allows it. This is the reason why
> ByRef must be specified noth at function declaration and at function call.
>
> Moreover, you can see that ByRef makes the function call slower because of
> the needed checks and the recall of the value from the stack.

Message understood!!! :-)))
Thank you very much!

Greetz
Stevie





More information about the User mailing list