Date: 02-16-2022
Return to Index
created by gbSnippets
To declare a variable as an object variable, requires 2 steps.
First, create a variable where an Interface is used instead of a data type.
Local X As MyObjectInterface
Second, assign an object reference to the variable, using the CLASS name.
Let X = MyObject
Here are both steps together:
Local X As MyObjectInterface
Let X = MyObject
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
#Include "Win32API.inc"
Global hDlg as Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Local X as MyInterface
Local X = MyClass
End If
End Function
Class MyClass
Instance S As Long 'class variable
Interface MyInterface 'exported methods/variables
Inherit IUnknown 'inherit the base class
Property Get S 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
End Interface
End Class
'gbs_01344
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm