Revision [17734]
This is an old revision of KeyPgMemberFunction made by FxMwikki on 2015-08-01 06:20:37.
FUNCTION (Member)
Declares or defines a member procedure returning a value.
Syntax:
{ KeyPgType Type | KeyPgClass Class | KeyPgUnion Union } typename
KeyPgDeclare declare [ KeyPgStaticMember static | KeyPgConstMember const ] Function fieldname [calling convention specifier] [ KeyPgAlias alias external_name ] ( [ parameters ] ) KeyPgAs as DataType datatype [ KeyPgStatic Static ]
End { KeyPgType Type | KeyPgClass Class | KeyPgUnion Union }Parameters:
typename
fieldname
fieldname
name of the procedure
external_name
name of field as seen when externally linked
parameters
the parameters to be passed to the procedure
calling convention specifier Description:
Function members are accessed with KeyPgOpMemberAccess Operator . (Member access) or KeyPgOpPtrMemberAccess Operator -> (Pointer to member access) to call a member procedure that returns a value (a reference can also be returned by specifying KeyPgByrefFunction byref as return_type). The procedure may optionally accept parameters either KeyPgByval byval or KeyPgByref byref. typename be overloaded without explicit use of the KeyPgOverload Overload keyword.
typename is the name of the type for which the Function method is declared and defined. Name resolution for typename follows the same rules as procedures when used in a KeyPgNamespace Namespace.
A hidden KeyPgThis this parameter having the same type as typename is passed to non-static member procedures. KeyPgThis this is used to access the fields of the KeyPgType Type, KeyPgClass Class, or KeyPgUnion Union.
To access duplicated symbols defined outside the Type, use: .SomeSymbol (or ..SomeSymbol if inside a KeyPgWith With..End With block).
To access duplicated symbols defined outside the Type, use: .SomeSymbol (or ..SomeSymbol if inside a KeyPgWith With..End With block).
A KeyPgStaticMember Static (Member) may be declared using the Static specifier. A KeyPgConstMember Const (Member) may be declared using the Const specifier.
As for a normal KeyPgFunction Function, the return value of a Function member can be ignored in the calling code.
Examples:
#include "vbcompat.bi"
Type Date
value As Double
Declare Static Function Today() As Date
Declare Function Year() As Integer
Declare Function Month() As Integer
Declare Function Day() As Integer
End Type
Function Date.Today() As Date
Return Type(Now())
End Function
Function Date.Year() As Integer
Return ..Year(value)
End Function
Function Date.Month() As Integer
Return ..Month(value)
End Function
Function Date.Day() As Integer
Return ..Day(value)
End Function
Dim d As Date = Date.Today
Print "Year = "; d.Year
Print "Month = "; d.Month
Print "Day = "; d.Day
Type Date
value As Double
Declare Static Function Today() As Date
Declare Function Year() As Integer
Declare Function Month() As Integer
Declare Function Day() As Integer
End Type
Function Date.Today() As Date
Return Type(Now())
End Function
Function Date.Year() As Integer
Return ..Year(value)
End Function
Function Date.Month() As Integer
Return ..Month(value)
End Function
Function Date.Day() As Integer
Return ..Day(value)
End Function
Dim d As Date = Date.Today
Print "Year = "; d.Year
Print "Month = "; d.Month
Print "Day = "; d.Day
Dialect Differences:
- Only available in the CompilerOptlang -lang fb dialect.
See also:
Back to User Defined Types