Revision history for KeyPgStatic


Revision [21724]

Last edited on 2016-12-03 14:40:55 by fxm [One sentence refined]
Additions:
When used at procedure definition level (forbidden at declaration line level), ##**Static**## specifies [[ProPgStorageClasses|static storage]] for all local variables, objects and arrays, except temporary types and internal variables (objects not explicitly declared).
Deletions:
When used at procedure definition level (forbidden at declaration line level), ##**Static**## specifies [[ProPgStorageClasses|static storage]] for all local variables, objects and arrays, except temporary types (objects not explicitly declared).


Revision [21715]

Edited on 2016-11-25 16:48:52 by fxm [STATIC used at procedure definition does not apply to temporary types]
Additions:
When used at procedure definition level (forbidden at declaration line level), ##**Static**## specifies [[ProPgStorageClasses|static storage]] for all local variables, objects and arrays, except temporary types (objects not explicitly declared).
Deletions:
When used at procedure definition level (forbidden at declaration line level), ##**Static**## specifies [[ProPgStorageClasses|static storage]] for all local variables, objects and arrays, except temporary types (not explicitly declared).


Revision [21712]

Edited on 2016-11-25 12:47:33 by fxm [STATIC used at procedure definition does not applied on temporary types]
Additions:
When used at procedure definition level (forbidden at declaration line level), ##**Static**## specifies [[ProPgStorageClasses|static storage]] for all local variables, objects and arrays, except temporary types (not explicitly declared).
Deletions:
When used at procedure definition level (forbidden at declaration line level), ##**Static**## specifies [[ProPgStorageClasses|static storage]] for all local variables, objects and arrays.


Revision [21702]

Edited on 2016-11-15 04:35:30 by fxm [Rewording]
Additions:
When used at procedure definition level (forbidden at declaration line level), ##**Static**## specifies [[ProPgStorageClasses|static storage]] for all local variables, objects and arrays.
Deletions:
When used with module-level and member procedure declarations, ##**Static**## specifies [[ProPgStorageClasses|static storage]] for all local variables, objects and arrays.


Revision [21286]

Edited on 2016-04-01 07:58:16 by fxm [Added link to BYREF (variables)]
Additions:
- ##[[KeyPgByrefVariables|Byref (variables)]]##


Revision [21142]

Edited on 2016-03-13 10:59:40 by fxm [Formatting]

No Differences

Revision [20532]

Edited on 2016-02-10 16:08:59 by DkLwikki [Update link format]
Additions:
**Static** //symbol1// [ (//array-dimensions//) ] [[KeyPgAs|As]] [[DataType|DataType]] [ = //expression//] [, //symbol2// [ (//array-dimensions//) ] [[KeyPgAs|As]] [[DataType|DataType]] [ = //expression//], ...]
**Static** [[KeyPgAs|As]] [[DataType|DataType]] //symbol1// [ (//array-dimensions//) ] [ = //expression//] [, //symbol2// [ (//array-dimensions//) ] [ = //expression//], ...]
[[KeyPgSub|Sub]]|[[KeyPgFunction|Function]] //procedurename// ( //parameters// ) [[[KeyPgAs|As]] [[DataType|DataType]]] **Static**
[[KeyPgEndblock|End]] [[KeyPgSub|Sub]]|[[KeyPgFunction|Function]]
##//lower-bound// [[KeyPgTo|To]] //upper-bound// [, ...]##
##[[KeyPgAny|Any]] [, [[KeyPgAny|Any]]...]##
An constant expression, or an array of constant expressions
Specifies [[ProPgStorageClasses|static storage]] for variables, objects and arrays; they are allocated at program startup and deallocated upon exit. Objects are constructed once when they are defined, and destructed upon program exit.
When declaring static arrays, only [[ProPgLiterals|numeric literals]], [[KeyPgConst|constants]] or [[KeyPgEnum|enumerations]] may be used as subscript range values. Static variable-length arrays must be declared empty (no subscript range list) and resized using ##[[KeyPgRedim|Redim]]## before used.
In both iterative and recursive blocks, like looping [[CatPgControlFlow|control flow statements]] or procedures, static variables, objects and arrays local to the block are guaranteed to occupy the same storage across all instantiations of the block. For example, procedures that call themselves - either directly or indirectly - share the same instances of their local static variables.
When used with module-level and member procedure declarations, ##**Static**## specifies [[ProPgStorageClasses|static storage]] for all local variables, objects and arrays.
At module-level variable declaration only, the modifier ##[[KeyPgShared|Shared]]## may be used with the keyword ##**Static**## to make module-level static variables visible inside procedures.
When used with in a user-defined type, ##**Static**## creates [[KeyPgStaticMember|static member procedures or variables]].
- Variables cannot be initialised in the //[[CompilerOptlang|-lang qb]]// dialect.
- ##[[KeyPgStaticMember|Static (Member)]]##
- ##[[KeyPgDim|Dim]]##, ##[[KeyPgRedim|Redim]]##
- ##[[KeyPgShared|Shared]]##
- ##[[KeyPgSub|Sub (Module)]]##, ##[[KeyPgFunction|Function (Module)]]##
- ##[[KeyPgMemberSub|Sub (Member)]]##, ##[[KeyPgMemberFunction|Function (Member)]]##
- ##[[KeyPgOptionstatic|Option Static]]##
- ##[[ProPgStorageClasses|Storage Classes]]##
Deletions:
**Static** //symbol1// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]] [ = //expression//] [, //symbol2// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]] [ = //expression//], ...]
**Static** [[KeyPgAs As]] [[DataType DataType]] //symbol1// [ (//array-dimensions//) ] [ = //expression//] [, //symbol2// [ (//array-dimensions//) ] [ = //expression//], ...]
[[KeyPgSub Sub]]|[[KeyPgFunction Function]] //procedurename// ( //parameters// ) [[[KeyPgAs As]] [[DataType DataType]]] **Static**
[[KeyPgEndblock End]] [[KeyPgSub Sub]]|[[KeyPgFunction Function]]
##//lower-bound// [[KeyPgTo To]] //upper-bound// [, ...]##
##[[KeyPgAny Any]] [, [[KeyPgAny Any]]...]##
An constant expression, or an array of constant expressions
Specifies [[ProPgStorageClasses static storage]] for variables, objects and arrays; they are allocated at program startup and deallocated upon exit. Objects are constructed once when they are defined, and destructed upon program exit.
When declaring static arrays, only [[ProPgLiterals numeric literals]], [[KeyPgConst constants]] or [[KeyPgEnum enumerations]] may be used as subscript range values. Static variable-length arrays must be declared empty (no subscript range list) and resized using ##[[KeyPgRedim Redim]]## before used.
In both iterative and recursive blocks, like looping [[CatPgControlFlow control flow statements]] or procedures, static variables, objects and arrays local to the block are guaranteed to occupy the same storage across all instantiations of the block. For example, procedures that call themselves - either directly or indirectly - share the same instances of their local static variables.
When used with module-level and member procedure declarations, ##**Static**## specifies [[ProPgStorageClasses static storage]] for all local variables, objects and arrays.
At module-level variable declaration only, the modifier ##[[KeyPgShared Shared]]## may be used with the keyword ##**Static**## to make module-level static variables visible inside procedures.
When used with in a user-defined type, ##**Static**## creates [[KeyPgStaticMember static member procedures or variables]].
- Variables cannot be initialised in the //[[CompilerOptlang -lang qb]]// dialect.
- ##[[KeyPgStaticMember Static (Member)]]##
- ##[[KeyPgDim Dim]]##, ##[[KeyPgRedim Redim]]##
- ##[[KeyPgShared Shared]]##
- ##[[KeyPgSub Sub (Module)]]##, ##[[KeyPgFunction Function (Module)]]##
- ##[[KeyPgMemberSub Sub (Member)]]##, ##[[KeyPgMemberFunction Function (Member)]]##
- ##[[KeyPgOptionstatic Option Static]]##
- ##[[ProPgStorageClasses Storage Classes]]##


Revision [17289]

Edited on 2014-09-23 11:30:51 by CountingPine [Variable initialisation is disallowed in -lang qb]
Additions:
{{fbdoc item="lang"}}
- Variables cannot be initialised in the //[[CompilerOptlang -lang qb]]// dialect.


Revision [17287]

Edited on 2014-09-23 11:24:17 by CountingPine [Add initialisation to syntax, use initialisation in example]
Additions:
**Static** //symbol1// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]] [ = //expression//] [, //symbol2// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]] [ = //expression//], ...]
**Static** [[KeyPgAs As]] [[DataType DataType]] //symbol1// [ (//array-dimensions//) ] [ = //expression//] [, //symbol2// [ (//array-dimensions//) ] [ = //expression//], ...]
##//expression//##
An constant expression, or an array of constant expressions
'' times called is initially 0
Deletions:
**Static** //symbol1// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]] [, //symbol2// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]], ...]
**Static** [[KeyPgAs As]] [[DataType DataType]] //symbol1// [ (//array-dimensions//) ] [, //symbol2// [ (//array-dimensions//) ], ...]
'' initialise timesCalled to 0


Revision [17286]

Edited on 2014-09-23 11:18:15 by CountingPine [Rename static variable in example, and initialise it.]
Additions:
'' initialise timesCalled to 0
static timesCalled as integer = 0
timesCalled += 1
Print "Number of times called: " & timesCalled
Deletions:
'' static variables are initialized to 0 by default
static i as integer
i += 1
Print "Number of times called: " & i


Revision [17152]

Edited on 2014-08-07 10:36:35 by FxMwikki [Added alternative syntax]
Additions:
**Static** //symbol1// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]] [, //symbol2// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]], ...]
**Static** [[KeyPgAs As]] [[DataType DataType]] //symbol1// [ (//array-dimensions//) ] [, //symbol2// [ (//array-dimensions//) ], ...]
Deletions:
**Static** //symbol// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]] [, ...]


Revision [17068]

Edited on 2014-04-28 09:07:42 by DkLwikki [Remove differences to QB note about static member]
Deletions:
- Using ##**Static**## to specify static member variables (and also ##[[KeyPgStaticMember Static]]## member procedures) is new to ""FreeBASIC"".


Revision [17050]

Edited on 2014-04-27 00:15:56 by FxMwikki [Move example for static member vars to KeyPgStaticMember]
Deletions:
{{fbdoc item="filename" value="examples/manual/variable/static2.bas"}}%%(freebasic)
'Assign an unique ID to every instance of a Type (ID incremented in order of creation)
Type UDT
Public:
Declare Property getID () As integer
Declare Constructor ()
Private:
Dim As Integer ID
Static As Integer countID
End Type
Dim As Integer UDT.countID = 0
Property UDT.getID () As Integer
Property = This.ID
End Property
Constructor UDT ()
This.ID = UDT.countID
UDT.countID += 1
End Constructor
Dim As UDT uFirst
Dim as UDT uSecond
Dim As UDT uThird
Print uFirst.getID
Print uSecond.getID
Print uThird.getID%%


Revision [17048]

Edited on 2014-04-26 12:58:14 by DkLwikki [Move static member vars to KeyPgStaticMember]
Additions:
##[[KeyPgAny Any]] [, [[KeyPgAny Any]]...]##
Deletions:
##[[KeyPgAny Any]] [, [[KeyPgAny Any]]...]


Revision [17047]

Edited on 2014-04-26 12:57:57 by DkLwikki [Move static member vars to KeyPgStaticMember]
Additions:
##[[KeyPgAny Any]] [, [[KeyPgAny Any]]...]
//or empty.//
When used with in a user-defined type, ##**Static**## creates [[KeyPgStaticMember static member procedures or variables]].
Deletions:
[[KeyPgType Type]] //typename//
**Static** //symbol// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]] [, ...]
[[KeyPgEndblock End]] [[KeyPgType Type]]
[[KeyPgDim Dim]] //typename.symbol// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]] [= //initial-value//] [, ...]
When used with UDT, a ##**Static**## member variable is created and initialized only once independently of any object construction, in contrast to non-static member variables which are created again and again, for each separate object.
Each ##**Static**## member variable needs an explicit definition as well as a declaration. The declaration inside the UDT is the prototype that is visible to every module seeing the UDT declaration (like with methods). The definition - which must be done outside the type declaration code, and appear only once in a single module - allocates static space for - and optionally initializes - the static variable.
A ##**Static**## member variable is subject to member access control except for its definition (outside the UDT). If a private ##**Static**## member variable is to be explicitly initialized outside the UDT member procedures, an initializer must be provided with the definition.
A (public) ##**Static**## member variable is visible throughout the entire program (inside any procedure) even if the modifier ##[[KeyPgShared Shared]]## is not specified in the definition (##**Static**## and ##[[KeyPgShared Shared]]## are useless in the definition, but this may improve code readability). So, (public) ##**Static**## member variables can be called directly anywhere in code, or on objects of type ##//typename//##.
As a ##**Static**## member variable is like a global variable declared in the UDT namespace, all variable kinds are authorized, even including variable-length arrays (only case where a data is ##**Static**## as UDT member, and is dynamic as variable).
##[[KeyPgStaticMember Static (Member)]]## is also used in member procedure declarations to specify static member procedures.


Revision [17004]

Edited on 2014-02-27 11:57:39 by FxMwikki [Reorganized 2 sentences in paragraph about the static member variable]
Additions:
When used with UDT, a ##**Static**## member variable is created and initialized only once independently of any object construction, in contrast to non-static member variables which are created again and again, for each separate object.
Each ##**Static**## member variable needs an explicit definition as well as a declaration. The declaration inside the UDT is the prototype that is visible to every module seeing the UDT declaration (like with methods). The definition - which must be done outside the type declaration code, and appear only once in a single module - allocates static space for - and optionally initializes - the static variable.
Deletions:
When used with UDT, each ##**Static**## member variable needs an explicit definition as well as a declaration. The declaration inside the UDT is the prototype that is visible to every module seeing the UDT declaration (like with methods). The definition - which must be done outside the type declaration code, and appear only once in a single module - allocates static space for - and optionally initializes - the static variable.
Such a ##**Static**## member variable is created and initialized only once independently of any object construction, in contrast to non-static member variables which are created again and again, for each separate object.


Revision [17001]

Edited on 2014-01-18 13:35:33 by FxMwikki [To highlight that static member data are created only once in contrast to non-static member data]
Additions:
Such a ##**Static**## member variable is created and initialized only once independently of any object construction, in contrast to non-static member variables which are created again and again, for each separate object.
Deletions:
Such a data member is created and initialized only once independently of any object construction, in contrast to non-static data members which are created again and again, for each separate object.


Revision [17000]

Edited on 2014-01-18 11:50:21 by FxMwikki [To highlight that static member data are created only once in contrast to non-static member data]
Additions:
Such a data member is created and initialized only once independently of any object construction, in contrast to non-static data members which are created again and again, for each separate object.


Revision [16985]

Edited on 2013-12-26 04:02:51 by FxMwikki [A static member variable can be a var-len array (static as UDT member and dynamic as variable)]
Additions:
As a ##**Static**## member variable is like a global variable declared in the UDT namespace, all variable kinds are authorized, even including variable-length arrays (only case where a data is ##**Static**## as UDT member, and is dynamic as variable).
Deletions:
As a ##**Static**## member variable is like a global variable declared in the UDT namespace, all variable kinds are authorized including variable-length arrays (only case where a data is ##**Static**## as UDT member, and is dynamic as variable).


Revision [16984]

Edited on 2013-12-26 03:54:25 by FxMwikki [A static member variable can be a variable-length array(static as UDT member and dynamic as variable]
Additions:
As a ##**Static**## member variable is like a global variable declared in the UDT namespace, all variable kinds are authorized including variable-length arrays (only case where a data is ##**Static**## as UDT member, and is dynamic as variable).
Deletions:
As a ##**Static**## member variable is like a global variable declared in the UDT namespace, all variable kinds are authorized including variable-length arrays.


Revision [16983]

Edited on 2013-12-14 07:39:47 by FxMwikki [A static member variable can be a variable-length array]
Additions:
As a ##**Static**## member variable is like a global variable declared in the UDT namespace, all variable kinds are authorized including variable-length arrays.


Revision [16960]

Edited on 2013-09-22 09:49:16 by FxMwikki [Added details on access control for static member variables]
Additions:
A ##**Static**## member variable is subject to member access control except for its definition (outside the UDT). If a private ##**Static**## member variable is to be explicitly initialized outside the UDT member procedures, an initializer must be provided with the definition.
Deletions:
A ##**Static**## member variable is subject to member access control except for its definition (outside the UDT). If a private ##**Static**## member variable is to be explicitly initialized outside the UDT, an initializer must be provided with the definition.


Revision [16959]

Edited on 2013-09-22 04:52:33 by FxMwikki [Added details on access control for static member variables]
Additions:
A ##**Static**## member variable is subject to member access control except for its definition (outside the UDT). If a private ##**Static**## member variable is to be explicitly initialized outside the UDT, an initializer must be provided with the definition.
A (public) ##**Static**## member variable is visible throughout the entire program (inside any procedure) even if the modifier ##[[KeyPgShared Shared]]## is not specified in the definition (##**Static**## and ##[[KeyPgShared Shared]]## are useless in the definition, but this may improve code readability). So, (public) ##**Static**## member variables can be called directly anywhere in code, or on objects of type ##//typename//##.
Deletions:
A ##**Static**## member variable is visible throughout the entire program (inside any procedure) even if the modifier ##[[KeyPgShared Shared]]## is not specified in the definition (##**Static**## and ##[[KeyPgShared Shared]]## are useless in the definition, but this may improve code readability). So, ##**Static**## member variables can be called directly anywhere in code, or on objects of type ##//typename//##.


Revision [16942]

Edited on 2013-09-08 11:25:48 by FxMwikki [Added a detail in one sentence (same as for KeyPgStaticMember)]
Additions:
A ##**Static**## member variable is visible throughout the entire program (inside any procedure) even if the modifier ##[[KeyPgShared Shared]]## is not specified in the definition (##**Static**## and ##[[KeyPgShared Shared]]## are useless in the definition, but this may improve code readability). So, ##**Static**## member variables can be called directly anywhere in code, or on objects of type ##//typename//##.
Deletions:
A ##**Static**## member variable is visible throughout the entire program (inside any procedure) even if the modifier ##[[KeyPgShared Shared]]## is not specified in the definition (##**Static**## and ##[[KeyPgShared Shared]]## are useless in the definition). So, ##**Static**## member variables can be called directly anywhere in code, or on objects of type ##//typename//##.


Revision [16883]

Edited on 2013-07-15 14:06:59 by DkLwikki [Fix formatting]
Additions:
**Static** //symbol// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]] [, ...]
**Static** //symbol// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]] [, ...]
[[KeyPgDim Dim]] //typename.symbol// [ (//array-dimensions//) ] [[KeyPgAs As]] [[DataType DataType]] [= //initial-value//] [, ...]
Deletions:
**Static** //symbol// [ (array-dimensions) ] [[KeyPgAs As]] [[DataType DataType]] [, ...]
**Static** //symbol// [ (array-dimensions) ] [[KeyPgAs As]] [[DataType DataType]] [, ...]
[[KeyPgDim Dim]] //typename.symbol// [ (array-dimensions) ] [[KeyPgAs As]] [[DataType DataType]] [= //initial-value//] [, ...]


Revision [16882]

Edited on 2013-07-15 14:06:16 by DkLwikki [Clean up syntax demo, add static member var initializer on DIM line]
Additions:
**Static** //symbol// [ (array-dimensions) ] [[KeyPgAs As]] [[DataType DataType]] [, ...]


[[KeyPgType Type]] //typename//
**Static** //symbol// [ (array-dimensions) ] [[KeyPgAs As]] [[DataType DataType]] [, ...]
[[KeyPgEndblock End]] [[KeyPgType Type]]
[[KeyPgDim Dim]] //typename.symbol// [ (array-dimensions) ] [[KeyPgAs As]] [[DataType DataType]] [= //initial-value//] [, ...]
[[KeyPgSub Sub]]|[[KeyPgFunction Function]] //procedurename// ( //parameters// ) [[[KeyPgAs As]] [[DataType DataType]]] **Static**
[[KeyPgEndblock End]] [[KeyPgSub Sub]]|[[KeyPgFunction Function]]
##//array-dimensions//##
##//lower-bound// [[KeyPgTo To]] //upper-bound// [, ...]##
Deletions:
**Static** //symbol// [ ( [ //subscripts// ] ) ] [ [[KeyPgAs as]] [[DataType DataType]] ] [ , ... ]
{ [[KeyPgSub sub]]|[[KeyPgFunction function]] } //proc_header// **Static**
[ ... ]
[[KeyPgEndblock end]] { [[KeyPgSub sub]]|[[KeyPgFunction function]] }
{ [[KeyPgType Type]] | [[KeyPgClass Class]] } //typename//
**Static** //symbol// [ ( [ //subscripts// ] ) ] [ [[KeyPgAs as]] [[DataType DataType]] ] [ , ... ]
End { [[KeyPgType Type]] | [[KeyPgClass Class]] }
[[KeyPgDim Dim]] //typename.symbol// [ ( [ //subscripts// ] ) ] [ [[KeyPgAs as]] [[DataType DataType]] ] [ , ... ]
##//subscripts//##
a comma-separated list of subscript ranges.
##//proc_header//##
procedure header for a procedure definition.


Revision [16727]

Edited on 2013-04-27 08:21:03 by FxMwikki [wording]
Additions:
A ##**Static**## member variable is visible throughout the entire program (inside any procedure) even if the modifier ##[[KeyPgShared Shared]]## is not specified in the definition (##**Static**## and ##[[KeyPgShared Shared]]## are useless in the definition). So, ##**Static**## member variables can be called directly anywhere in code, or on objects of type ##//typename//##.
Deletions:
A ##**Static**## member variable is visible throughout the entire program (inside any procedure) even if the modifier ##[[KeyPgShared Shared]]## is not specified in the second declaration (##**Static**## and ##[[KeyPgShared Shared]]## are useless in the second declaration). So, ##**Static**## member variables can be called directly anywhere in code, or on objects of type ##//typename//##.


Revision [16676]

Edited on 2013-03-23 18:49:16 by CountingPine [second declaration = definition]
Additions:
When used with UDT, each ##**Static**## member variable needs an explicit definition as well as a declaration. The declaration inside the UDT is the prototype that is visible to every module seeing the UDT declaration (like with methods). The definition - which must be done outside the type declaration code, and appear only once in a single module - allocates static space for - and optionally initializes - the static variable.
A ##**Static**## member variable is visible throughout the entire program (inside any procedure) even if the modifier ##[[KeyPgShared Shared]]## is not specified in the second declaration (##**Static**## and ##[[KeyPgShared Shared]]## are useless in the second declaration). So, ##**Static**## member variables can be called directly anywhere in code, or on objects of type ##//typename//##.
Deletions:
When used with UDT, each ##**Static**## member variable needs an additional declaration. The declaration inside the UDT is the prototype that is visible to every module seeing the UDT declaration (like with methods). The second declaration (outside the UDT), only needed once in the whole program, allocates and optionally initializes the static variable.
A ##**Static**## member variable is visible throughout the entire program (inside any procedure) even if the modifier ##[[KeyPgShared Shared]]## is not specified in the second declaration (##**Static**## and ##[[KeyPgShared Shared]]## are useless in the second declaration). So, ##**Static**## member variables can be called directly anywhere in code, or on objects of type //typename//.


Revision [16673]

Edited on 2013-03-23 11:48:05 by FxMwikki [Wording]
Additions:
When used with UDT, each ##**Static**## member variable needs an additional declaration. The declaration inside the UDT is the prototype that is visible to every module seeing the UDT declaration (like with methods). The second declaration (outside the UDT), only needed once in the whole program, allocates and optionally initializes the static variable.
- Using ##**Static**## to specify static member variables (and also ##[[KeyPgStaticMember Static]]## member procedures) is new to ""FreeBASIC"".
Deletions:
When used with UDT, each ##**Static**## member variable needs an additional declaration. The declaration inside the UDT is the prototype that is visible to every module seeing the UDT declaration (like with methods). The second declaration, only needed once in the whole program, may initialize the global variable.
- Using ##[[KeyPgStaticMember Static]]## to specify static member procedures is new to ""FreeBASIC"".


Revision [16672]

Edited on 2013-03-23 09:27:25 by FxMwikki [Formatting]
Additions:
...


Revision [16671]

Edited on 2013-03-23 09:00:45 by FxMwikki [Complement for access rules to static member variable]
Additions:
A ##**Static**## member variable is visible throughout the entire program (inside any procedure) even if the modifier ##[[KeyPgShared Shared]]## is not specified in the second declaration (##**Static**## and ##[[KeyPgShared Shared]]## are useless in the second declaration). So, ##**Static**## member variables can be called directly anywhere in code, or on objects of type //typename//.
Deletions:
A ##**Static**## member variable is visible throughout the entire program (inside any procedure) even if the modifier ##[[KeyPgShared Shared]]## is not specified in the second declaration (##**Static**## and ##[[KeyPgShared Shared]]## are useless in the second declaration).


Revision [16669]

Edited on 2013-03-23 07:32:10 by FxMwikki [Added example in order to complete the information for static member variables]
Additions:
{{fbdoc item="filename" value="examples/manual/variable/static2.bas"}}%%(freebasic)
'Assign an unique ID to every instance of a Type (ID incremented in order of creation)
Type UDT
Public:
Declare Property getID () As integer
Declare Constructor ()
Private:
Dim As Integer ID
Static As Integer countID
End Type
Dim As Integer UDT.countID = 0
Property UDT.getID () As Integer
Property = This.ID
End Property
Constructor UDT ()
UDT.countID += 1
This.ID = UDT.countID
End Constructor
Dim As UDT uFirst
Dim as UDT uSecond
Dim As UDT uThird
Print uFirst.getID
Print uSecond.getID
Print uThird.getID%%


Revision [16668]

Edited on 2013-03-23 05:42:26 by FxMwikki [Added information for static member variables]
Additions:
{ [[KeyPgType Type]] | [[KeyPgClass Class]] } //typename//
**Static** //symbol// [ ( [ //subscripts// ] ) ] [ [[KeyPgAs as]] [[DataType DataType]] ] [ , ... ]
End { [[KeyPgType Type]] | [[KeyPgClass Class]] }
[[KeyPgDim Dim]] //typename.symbol// [ ( [ //subscripts// ] ) ] [ [[KeyPgAs as]] [[DataType DataType]] ] [ , ... ]
When used with UDT, each ##**Static**## member variable needs an additional declaration. The declaration inside the UDT is the prototype that is visible to every module seeing the UDT declaration (like with methods). The second declaration, only needed once in the whole program, may initialize the global variable.
A ##**Static**## member variable is visible throughout the entire program (inside any procedure) even if the modifier ##[[KeyPgShared Shared]]## is not specified in the second declaration (##**Static**## and ##[[KeyPgShared Shared]]## are useless in the second declaration).


Revision [15757]

Edited on 2012-01-22 09:02:12 by FxMwikki [Add 'Static Shared']
Additions:
At module-level variable declaration only, the modifier ##[[KeyPgShared Shared]]## may be used with the keyword ##**Static**## to make module-level static variables visible inside procedures.
Deletions:
At module-level variable declaration only, the modifier ##[[KeyPgShared Shared]]## may be used with the keyword ##**Static**## to make module-level variables visible inside procedures.


Revision [15755]

Edited on 2012-01-22 08:53:51 by FxMwikki [Add 'Static Shared']
Additions:
At module-level variable declaration only, the modifier ##[[KeyPgShared Shared]]## may be used with the keyword ##**Static**## to make module-level variables visible inside procedures.


Revision [15752]

Edited on 2012-01-22 07:13:01 by FxMwikki [Add 'Shared' in the links list]
Additions:
- ##[[KeyPgShared Shared]]##


Revision [15574]

Edited on 2011-12-20 03:33:32 by FxMwikki [Static variable may only be initialised with constant value]
Additions:
A static variable may only be initialised with a constant value: its starting value is set at the start of the program before any code is run, and so it cannot depend on any variables or functions in it.


Revision [13449]

The oldest known version of this page was created on 2008-06-24 15:54:03 by MaDdogg6 [Static variable may only be initialised with constant value]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode