FreeBASIC マニュアルのトップに戻る

FreeBASIC StaticMember

目次→命令文→手続きSTATIC (Member)←オリジナル・サイト

STATIC (メンバー) 左にメニュー・フレームが表示されていない場合は、ここをクリックして下さい

←リンク元に戻る プログラム開発関連に戻る

静的メンバー手続きと変数のための宣言指定子。

構文:
Type typename
Static variablename As DataType [, ...]
Declare Static Sub|Function procedurename ...
...

End Type

Dim typename.variablename As DataType [= initializer] [, ...]

[Static] Sub|Function typename.procedurename ...

...
End Sub|Function

記述:


例:
'' 実行時にメンバーによって起動された実際の手続きを設定する方法を示す例。
'' 静的メンバー手続きを用います。
Type _Object

  Enum handlertype
    ht_default
    ht_A
    ht_B
  End Enum

  Declare Constructor( ByVal ht As handlertype = ht_default)

  Declare Sub handler()

Private:
  Declare Static Sub handler_default( ByRef obj As _Object )
  Declare Static Sub handler_A( ByRef obj As _Object )
  Declare Static Sub handler_B( ByRef obj As _Object )
  handler_func As Sub( ByRef obj As _Object )

End Type

Constructor _Object( ByVal ht As handlertype )
  Select Case ht
  Case ht_A
    handler_func = @_Object.handler_A
  Case ht_B
    handler_func = @_Object.handler_B
  Case Else
    handler_func = @_Object.handler_default
  End Select
End Constructor

Sub _Object.handler()
  handler_func(This)
End Sub

Sub _Object.handler_default( ByRef obj As _Object )
  Print "デフォルトメソッドを使った取り扱い"
End Sub

Sub _Object.handler_A( ByRef obj As _Object )
  Print "メソッドAを使った取り扱い"
End Sub

Sub _Object.handler_B( ByRef obj As _Object )
  Print "メソッドBを使った取り扱い"
End Sub

Dim objects(1 To 4) As _Object => _
  { _
    _Object.handlertype.ht_B, _
    _Object.handlertype.ht_default, _
    _Object.handlertype.ht_A _
  }
  '' 配列の第4項目は、 _Object.handlertype.ht_default です

For i As Integer = 1 To 4
  Print i,
  objects(i).handler()
Next i



'' 型のすべてのインスタンスに、ユニークなIDを割り当てます(生成の順に増分された ID)。

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



QBからの違い:

参照:
手続きに戻る
ユーザ定義型 に戻る
←リンク元に戻る プログラム開発関連に戻る

ページ歴史:2023-07-09 02:34:50
日本語翻訳:WATANABE Makoto、原文著作者:JeffMarshall

ホームページのトップに戻る

表示-非営利-継承