Gambas文档
主题
代码片段
名词解释
如何操作
应用程序仓库
废弃的组件
开发环境文档
开发者文档
教程
文档
最新修改
组件
维基手册
维基搜索
维基许可协议
编译和安装
语言概览
语言索引
#Else
#Endif
#If
+INF
-INF
Abs
Access
ACos
ACosh
Alloc
AND
AND IF
Ang
APPEND
AS
Asc
ASin
ASinh
Asl
Asr
ASSERT
ATan
ATan2
ATanh
Base$
Base64$
BChg
BClr
BEGINS
Bin$
Boolean@
BREAK
BSet
BTst
BYREF
Byte@
CASE
CATCH
CBool
Cbr
CByte
CDate
Ceil
CFloat
CHGRP
CHMOD
Choose
CHOWN
Chr$
CInt
CLASS
CLong
CLOSE
Comp
CONST
CONTINUE
Conv$
COPY
Cos
Cosh
CPointer
CREATE
CREATE PRIVATE
CREATE STATIC
CShort
CSingle
CStr
CString
CVariant
Date
Date@
DateAdd
DateDiff
Day
DConv$
DEBUG
DEC
Dec
DEFAULT
Deg
DFree
DIM
Dir
DIV
DO
DOWNTO
EACH
ELSE
END
ENDIF
ENDS
END SELECT
END STRUCT
END WITH
ENUM
Eof
ERROR
ERROR TO
Eval
Even
EVENT
EXEC
Exist
Exp
Exp2
Exp10
Expm
EXPORT
EXTERN
FALSE
FAST
FAST UNSAFE
FINALLY
Fix
Float@
Floor
FLUSH
FOR
FOR EACH
Format$
Frac
Free
FromBase
FromBase64$
FromUrl$
FUNCTION
GOSUB
GOTO
Hex$
Hour
Html$
Hyp
IF
IIf
IN
INC
INCLUDE or #INCLUDE
INHERITS
INPUT
INPUT FROM
InStr
Int
Int@
Integer@
IS
IsAlnum
IsAscii
IsBlank
IsBoolean
IsDate
IsDigit
IsDir
IsFloat
IsHexa
IsInf
IsInteger
IsLCase
IsLetter
IsLong
IsLower
IsMissing
IsNaN
IsNull
IsNumber
IsPunct
IsSpace
IsUCase
IsUpper
KILL
LAST
LCase$
Left$
Len
LET
LIBRARY
LIKE
LINE INPUT
LINK
LOCK
Lof
Log
Log2
Log10
Logp
Long@
LOOP
Lsl
Lsr
LTrim$
Mag
MATCH
Max
ME
Mid$
Min
Minute
MkBool$
MkBoolean$
MkByte$
MkDate$
MKDIR
MkFloat$
MkInt$
MkInteger$
MkLong$
MkPointer$
MkShort$
MkSingle$
MOD
Month
MOVE
NEW
NEXT
NOT
Now
NULL
Oct$
Odd
ON GOSUB
ON GOTO
OPEN
OPEN MEMORY
OPEN MEMORY
OPEN NULL
OPEN PIPE
OPEN PIPE
OPEN STRING
OPTIONAL
OR
OR IF
OUTPUT
OUTPUT TO
PEEK
Pi
Pointer@
PRINT
PRIVATE
PROCEDURE
PROPERTY
PUBLIC
QUIT
Quote$
Rad
RAISE
Rand
RANDOMIZE
RDir
READ
Realloc
REPEAT
Replace$
RETURN
Right$
RInStr
RMDIR
Rnd
Rol
Ror
Round
RTrim$
Scan
SConv$
Second
Seek
SEEK
SELECT
Sgn
SHELL
Shell$
Shl
Short@
Shr
Sin
Single@
Sinh
SizeOf
SLEEP
Space$
Split
Sqr
Stat
STATIC
STEP
STOP
STOP EVENT
Str$
Str@
String$
String@
StrPtr
STRUCT
SUB
Subst$
SUPER
SWAP
Tan
Tanh
Temp$
THEN
Time
Timer
TO
Tr$
Trim$
TRUE
TRY
TypeOf
UCase$
UnBase64$
UNLOCK
Unquote$
UNTIL
Url$
USE
Val
VarPtr
WAIT
WATCH
Week
WeekDay
WEND
WHILE
WITH
WRITE
XOR
Year
专用方法
事件声明
事件循环
使用保留字作为标识符
内置数组
内置集合
变量声明
复数
外部函数声明
外部函数管理
字符串操作
局部变量声明
属性声明
常量声明
常量表达式
数据类型
数据类型的二进制表示形式
数组声明
方法声明
本地化和翻译函数
枚举声明
算术运算
结构体声明
行标号
语言常量
赋值
赋值操作
运算符优先级
逻辑运算
说明
错误消息

CREATE STATIC

CREATE STATIC

这些关键字被单独放置在类文件的起始位置时,将告知解释器“当将非静态标志作为类的名称时,在执行中将创建一个类的自动隐藏的实例”。

如果使用这个特性,类构造程序(特殊的方法 _new 将被无参数调用。

该特性已经被用于FormSettings类的内部。

以下是 Settings 类代码的摘录:

Example: Settings.class (gb.settings)

Export
Create Static

' ...

Public Sub _new(Optional Path As String, Optional Title As String)
  ' ...
    If Not Path Then
      Path = Settings.DefaultDir &/ Application.Name & ".conf"

Explanation

Consider this line of Gambas code:

Print Settings["Key"]

It looks like the array accessor method _get() is applied to the Settings class to get the value corresponding to the key "Key", but this doesn't make sense as the _get() method of Settings is not static but dynamic, i.e. it does not belong to the class but to some object of the class. But since Settings is CREATE STATIC, the interpreter will create the automatic instance of the Settings class behind the scenes and use this object for the array access.

The automatic instance of Settings is, as explained above, constructed without arguments. In the Settings.class code snippet above you see that in this case Path is set to the default configuration file path Settings.DefaultDir &/ Application.Name & ".conf".

In conclusion, whenever you use the class name "Settings" like an object (by using dynamic symbols on it), you actually use the hidden automatic instance of the Settings class, which is linked to the default configuration file.

Singletons

This feature, together with CREATE PRIVATE, can be used to implement the object-oriented programming singleton pattern. CREATE STATIC allows you to use a class name like an object while CREATE PRIVATE makes the class uninstantiable (except for the automatic instance).

Instead of a CREATE STATIC + CREATE PRIVATE class you can also effectively use a module in Gambas!

参见