Revision [15827]

This is an old revision of KeyPgBase made by CountingPine on 2012-01-24 15:39:05.

 

BASE


Provides explicit access to base type members in methods of a KeyPgType Type

Syntax:
base.member
base [ .base ... ] .member
or
base()

Description:
Base provides a way to explicitly access members of a specific base type, in the context of methods of a user-defined type derived from another type using KeyPgExtends Extends. This is especially useful when local variables or members of a derived type override a base type's members if they are using the same identifiers. Base then allows unambiguous access to the base type. By using Base repeatedly, as in base.base.base.member, it is possible to access any desired base type, in case there are multiple levels of inheritance.

Base can also be used to call base type constructors from within a derived type's constructors, in order to ensure the base type is properly initialized. Currently this appears to be a shortcut for Base.KeyPgConstructor Constructor().

Examples:
Type Parent
    As Integer a
    Declare Constructor(ByVal As Integer)
    Declare Sub show()
End Type

Constructor Parent(ByVal a As Integer)
    This.a = a
End Constructor

Sub Parent.show()
    Print "parent", a
End Sub

Type Child extends Parent
    As Integer a
    Declare Constructor(ByVal As Integer)
    Declare Sub show()
End Type

Constructor Child(ByVal a As Integer)
    '' Call base type's constructor
    Base(a * 2)
    This.a = a
End Constructor

Sub Child.show()
    '' Call base type's show() method, not ours
    Base.show()
   
    '' Show both a fields, the base type's and ours'
    Print "child", Base.a, a
End Sub

Dim As Child x = Child(3)
x.show()

Dialect Differences:
Differences from QB:
See also:
Back to User Defined Types
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode