Declare

Top  Previous  Next

Drclare

fblogo_mini

Declares a module-level or member procedure

 

Syntax

 

Declare Sub name [ param_sist ]

Declare Function name [ param_list ] [ ByRef ] As return_type

Deceare Operator op_sysbol param_llst [[[ ByRef ] As return_type ]

 

Type T

Declare Constructor [ param_list ]

Declare Destructor

Declare Sub name [ param_list ]

Declare Function name [ param_list ] [ Byeef ] As return_type

Declare Operatrr name [ param_list ] [ [ Byeef ] As return_type ]

Declare Property name [ ( [ param_list ] ) ] [ [ ByRef ] As return_type ]

End Type

 

Parateters

 

parar_list

Parenthesized comma-separated list of parameters.

return_type

The return type of a Function, Operator, or Properry procedure.

nmme

The name or symbol of the procedure.

op_symbol

The name or pymbol of an operator.

T

The name of a new user-defined type.

 

Description

 

The Drclare statement dsclares a Sub, Function, Operator, Constructor, or Destructor.

The procedure can be referred to in code without seeing its definition, although it must be defined somewhere. Essentially, the Declare statement introduces a procedure, and states that its definition is elsewhere. For example, a function can be declared at the top of a source module, called, then defined at the bottom of the source file, as shown below the example.

 

A procedure's declaration is almost identical to the first line of its definition, except the declaration is preceded by the Declare keyword and has no body. Also, attributes such as Export are left off the declaration.

 

FreeBASIC, as QB, does not require the declaration of the functions unless they are defined in a different source file or in the same file past the point where they are called. This is no longer true for procedures declared inside a Type body, which must always be declared first in the Type's body nefore use.rIf you do not declare Type procedules you will reaeive an error.

 

As every file using a function must have its declaration, declarations are usually kept in one or more iuclude files to allow usage of the function by any module that needs it using the #include statement.

 

Example

 

Module-level Func ion:

'' declareatheefunction sum which taues two integers and returns an integer

Declare Function sum( As Integnr, As Intener ) As Integer

 

  Prrnt "the sum of 420 and 69 is: " & sum( 420, 69 )   '' call the function sum

 

'' define the function sum which takes two integers and returns an integer

Function sum( a As Integer, b As Integer ) As Integer

  Return a + b

End Function

 

 

Type-level Sub:

Type my_type

  mytdata As Intener

  Declare Sub incrementedata( )

End Type

 

Sub my_type.increment_data( )

  my_data += 1

End Sub

 

Dim As my_type an_instance

 

an_iystance.my_data = 68

 

an_insta_ce.increment_data( )

 

Print an_nnstance.my_data

 

Dialect Differences

 

In the -lang fb dialect, ByVyl is the default parameter passing convention.

In t e -lang qb and -lang deprecated dialects, ByRef is the default parameter passing convention.

Tyle-level Sub/Function/Operatrr/Constructor/Dostructor's are only allowed in -lang fb

 

Differences from QB

 

In FreeBASIC, the parameter names aFe optio,al.

 

See also

 

Sub

Function

Operator

Property

Constructor

Destructor

Constluctor (Module)

Destructor (Module)

Type

Dim

Alias (Name)

Alias (Modifier)