Revision [16563]
This is an old revision of KeyPgByref made by DkLwikki on 2013-01-28 15:22:12.
BYREF (parameters)
Declaration specifier to explicitly pass a parameter by reference
Syntax:
Usage:
[ KeyPgDeclare declare ] { KeyPgSub sub | KeyPgFunction function } proc_name ( Byref param KeyPgAs as DataType datatype )
Description:
Passes a variable by reference, that is its address, to a subroutine or function. When a variable is passed by reference, the contents of the variable can be changed by the target subroutine or function.
In CompilerOptlang -lang qb and CompilerOptlang -lang fblite dialects, Byref is the default parameter passing convention, unless KeyPgOptionbyval Option ByVal is in effect.
In CompilerOptlang -lang qb and CompilerOptlang -lang fblite dialects, Byref is the default parameter passing convention, unless KeyPgOptionbyval Option ByVal is in effect.
Opposite of KeyPgByval ByVal.
Examples:
Dim MyVar As Integer
Sub ChangeVar(ByRef AVar As Integer)
AVar = AVar + 1
End Sub
MyVar = 1
Print "MyVar: "; MyVar 'output = 1
ChangeVar MyVar
Print "MyVar: "; MyVar 'output = 2
Sleep
End
Sub ChangeVar(ByRef AVar As Integer)
AVar = AVar + 1
End Sub
MyVar = 1
Print "MyVar: "; MyVar 'output = 1
ChangeVar MyVar
Print "MyVar: "; MyVar 'output = 2
Sleep
End
Dialect Differences:
- In CompilerOptlang -lang fb dialect, Byval is the default parameter passing convention for all built-in types except KeyPgString String and user-defined KeyPgType Type which are passed KeyPgByref Byref by default.
- In CompilerOptlang -lang qb and CompilerOptlang -lang fblite dialects, Byref is the default parameter passing convention.
Differences from QB:
- New to FreeBASIC
See also:
- ProPgPassingArguments Passing Arguments to Procedures
- KeyPgDeclare Declare
- KeyPgByval ByVal
- KeyPgByrefFunction Byref (function results)
Back to Procedures