|
Declare Statement |
Top Previous Next |
Function: |
Declares a function or a subroutine or a variable for later use. |
Syntax: |
declare function name [ ( [ byref ] argument1 as type1, [ byref ] argument2 as type2,...) ] as ret_type or: declare sub name [ ( [ byref ] argument1 as type1, [ byref ] argument2 as type2,…) ] or: declare name [ ( bounds1) ] [ , name2 [ ( bounds2 ) ] ] as type [ ( max_string_size ) ] |
Scope: |
Global and HTML |
See Also: |
Part |
Description |
function |
Optional. Used to specify that you are declaring a function procedure. |
sub |
Optional. Used to specify that you are declaring a sub procedure. If neither sub nor function appear, it is assumed that the declare is used to declare a variable. |
name |
Required. Used to specify the name of the function, sub or variable you are declaring. |
byref |
Optional. If present, arguments are passed by reference. If not, arguments are passed By Value. |
argument1[1, 2...] |
Optional. The name of the argument to be passed to the procedure. Only used if sub or function appear. |
as |
Required. Precedes the type definition. |
type[1, 2...] |
Optional (required if arguments are present). Specifies the type of the argument to be passed to the procedure. |
ret_type |
Optional (required for functions, cannot be used for subs). Used to specify the type of the return value from the procedure. |
bounds[1, 2...] |
Optional (used only when declaring variables). Specifies the boundary (finite size) of a dimension in an array. |
Details
In large projects, you often define a function or variable in one compilation unit, and use it from other units, so it is external to those units.
The unit which uses this external variable or function should refer to it in a way which lets the compiler know that it does indeed exist externally.
The declare statement is used to refer to a variable or function in this manner, but doesn't actually allocate any memory or produce any code; rather, it tells the compiler about this external entity, so that the compiler knows about it and can deal with it (see Dim Statement).
Usually, variables and functions which are shared between compilation units are declared in a header file, and this header is then included in the units (see Include Statement).
Example
declare function hittest(x as integer, y as integer) as boolean declare sub dosomething (s as byref string) declare devicestate as integer
|