Date: 02-16-2022
Return to Index
'Compilable Example: (Jose Includes)
created by gbSnippets
#Compiler PBWin 10
Function PBMain() As Long
Local Z As MyInterface 'z is object variable with interface MyInterface
Let Z = Class "MyClass" 'z is object of class "myclass". Interface is implied by object variable
? Str$(Z.x) 'uses Get
Z.MM 'uses exposed method MM
? Str$(Z.x) 'uses Get
Z.x = 14 'uses Set
? Str$(Z.x) 'uses Get
End Function
Class MyClass
'hidden stuff -----------------------------------------
Instance X As Long 'class variable
Class Method Create() : ? "Object created" : End Method 'startup method (optioanl)
Class Method Destroy() : ? "Object destroyed" : End Method 'end method (optional)
'exposed stuff -----------------------------------------
Interface MyInterface 'exported methods/variables
Inherit IUnknown 'inherit this base class
'note ... no Instance variable definitions
Property Get X As Long : Property = X : End Property 'Property Get parameters are optional
Property Set X (V As Long) : X = V : End Property 'Property Set requires at least 1 parameter
Method MM() : Incr X : End Method 'Exposed method
End Interface
End Class
'The 3 Base Classes (Interfaces) supported by PowerBASIC are:
' IUnKnown most basic interface definition, direct access
' IAutomation (derived from IUnKnown, direct access)
' IDispatch (derived from IUnKnown, direct and Dispatch access)
'Terminology notes:
'INHERIT CUSTOM is same as INHERIT IUNKNOWN
'INHERIT DUAL is same as INHERIT IDISPATCH
'INHERIT AUTOMATION is same as INHERIT IAutomation
'gbs_01342
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm