Yes, do it by hand. You have much more control over the code.
Using all the above references we devised a set of macros that allowed us to code classes without worrying about PB's quirky pointer syntax.
The following edited code shows the mainline module of one of our packages and its associated class. The "AppDesign" procedure would normally contain code to create the rest of the application, which is implemented entirely with classes.
Package mainline code:
Code: Select all
;===============================================
;
; start of package: DvsML06.pb
;
;===============================================
;
; This is the mainline code for the
; DVS Mildred package.
;
;===============================================
;
; common include files
;
IncludeFile "modConstant.pbi" ; Global Constants
IncludeFile "modMacro.pbi" ; Global Macros
IncludeFile "modStructure.pbi" ; Global Structures
;
;-----------------------------------------------
;
; file class interfaces
;
IncludeFile "objFile195.pbi" ; Structures
IncludeFile "objFile229.pbi" ; Constants
IncludeFile "objFile231.pbi" ; Modules
IncludeFile "objFile233.pbi" ; Elements
IncludeFile "objFile250.pbi" ; Messages
;
;-----------------------------------------------
;
; module class interfaces
;
IncludeFile "objApplication.pbi" ; Application Class
IncludeFile "objContainer.pbi" ; Container Class
IncludeFile "objDD.pbi" ; Data Dictionary Support Class
IncludeFile "objGadget.pbi" ; Generic Gadget Class
IncludeFile "objDvsam.pbi" ; Dvsam Class
;
;-----------------------------------------------
;
; program class interfaces
;
;
;-----------------------------------------------
;
; package class interface
;
IncludeFile "objDvsML06.pbi"
;
;-----------------------------------------------
;
; global objects
;
GlobalObject(gloApp, objApplication) ; 16138 : application object
GlobalObject(gloDD, objDD) ; 16397 : data dictionary support object
;
;-----------------------------------------------
;
; file classes
;
IncludeFile "clsFile195.pbi" ; Structures
IncludeFile "clsFile229.pbi" ; Constants
IncludeFile "clsFile231.pbi" ; Modules
IncludeFile "clsFile233.pbi" ; Elements
IncludeFile "clsFile250.pbi" ; Messages
;
;-----------------------------------------------
;
; module classes
;
IncludeFile "clsApplication.pbi" ; Application Class
IncludeFile "clsContainer.pbi" ; Container Class
IncludeFile "clsDD.pbi" ; Data Dictionary Support Class
IncludeFile "clsGadget.pbi" ; Generic Gadget Class
IncludeFile "clsDvsam.pbi" ; Dvsam Class
;
;-----------------------------------------------
;
; program classes
;
;
;-----------------------------------------------
;
; package class
;
IncludeFile "clsDvsML06.pbi"
;
;-----------------------------------------------
;
; create global objects
;
gloApp = CreateObject(Application) ; 16138 : application object
gloDD = CreateObject(DD) ; 16397 : data dictionary support object
;
;-----------------------------------------------
;
; package mainline
;
GlobalObject(gloDvsML06, objDvsML06)
gloDvsML06 = CreateObject(DvsML06)
ObjectCall(gloDvsML06, Main) ()
gloDvsML06 = DestroyObject(gloDvsML06)
;
;-----------------------------------------------
;
; destroy global objects
;
gloDD = DestroyObject(gloDD) ; 16397 : data dictionary support object
gloApp = DestroyObject(gloApp) ; 16138 : application object
;
;-----------------------------------------------
;
; end of package: DvsML06.pb
;
End
;
;===============================================
Package interface:
Code: Select all
;===============================================
;
; DvsML06 class interface : DVS Mildred
;
;===============================================
;
; Interface
;
DeclareExternalFunction(DvsML06, Create, typObject) ()
;
Interface objDvsML06
Func(Destroy, typObject) ()
Func(Clone, typObject) ()
Subr(Main) ()
EndInterface
;
;===============================================
; end of : DvsML06 Class Interface
;===============================================
Package class:
Code: Select all
;===============================================
;
; clsDvsML06.pbi : class methods : DVS Mildred
;
;===============================================
;
; Properties
;
Structure strDvsML06
;
; primary properties
;
FieldPointer(prpVirtualTable) ; 16393 : pointer to the class virtual table
Field(priReferenceCount, typInt32) ; 16394 : class reference count
;
; private properties
;
Field(proAppContainer, objContainer) ; 16085 : ref to the main application container object
;
EndStructure
;
;===============================================
;
; Private Declares
;
DeclarePrivateSubroutine(DvsML06, Constructor) (ByVal(Me, strDvsML06))
DeclarePrivateSubroutine(DvsML06, Destructor) (ByVal(Me, strDvsML06))
DeclarePrivateSubroutine(DvsML06, AppDesign) (ByVal(Me, strDvsML06))
;
;===============================================
;
; Primary Methods
;
;-----------------------------------------------
;
ExternalFunction(DvsML06, Create, typObject) ()
;
; Create create a class instance
;
Local(Me, strDvsML06)
Me = AllocateMemory(SizeOf(strDvsML06))
If IsObject(Me)
InitializeStructure(Me, strDvsML06)
Me\prpVirtualTable = LabelPtr(DvsML06, VirtualTable)
Me\priReferenceCount = 1
ClassCall(DvsML06, Constructor) (Me)
EndIf
ProcedureReturn Me
EndFunction
;
;-----------------------------------------------
;
ExternalFunction(DvsML06, Destroy, typObject) (ByVal(Me, strDvsML06))
;
; Destroy destroy a class instance
;
If IsObject(Me)
If Me\priReferenceCount > 1
Me\priReferenceCount = Me\priReferenceCount - 1
Else
ClassCall(DvsML06, Destructor) (Me)
ClearStructure(Me, strDvsML06)
FreeMemory(Me)
EndIf
EndIf
ProcedureReturn 0
EndFunction
;
;-----------------------------------------------
;
ExternalFunction(DvsML06, Clone, typObject) (ByVal(Me, strDvsML06))
;
; Clone clone a class instance
;
If IsObject(Me)
Me\priReferenceCount = Me\priReferenceCount + 1
EndIf
ProcedureReturn Me
EndFunction
;
;===============================================
;
; External Methods
;
;-----------------------------------------------
;
ExternalSubroutine(DvsML06, Main) (ByVal(Me, strDvsML06))
;
; Main package mainline procedure
;
Set(Me\proAppContainer, exsCaption, "DVS Mildred") ; 15328 : caption text
Set(Me\proAppContainer, exiBaseWidth, 1280) ; 16415 : nominal width of the gui object (pixels)
Set(Me\proAppContainer, exiBaseHeight, 800) ; 16416 : nominal height of the gui object (pixels)
Set(Me\proAppContainer, exlResizeAllowed, True) ; 16405 : true = gui object can be resized
Set(Me\proAppContainer, exlHorizontalAlignment, True) ; 16409 : true = horizontal gui object alignment is allowed
Set(Me\proAppContainer, exiHorizontalAlignmentMode, #iGUI_ALIGN_FILL) ; 16408 : fill, start, end, centre
Set(Me\proAppContainer, exlVerticalAlignment, True) ; 16411 : true = vertical gui object alignment is allowed
Set(Me\proAppContainer, exiVerticalAlignmentMode, #iGUI_ALIGN_FILL) ; 16410 : fill, start, end, centre
SetCallBack(Me\proAppContainer, expCBDesign, DvsML06, AppDesign) ; create a callback pointer
ObjectCall(Me\proAppContainer, Attach) () ; attach the application container
ObjectCall(gloApp, ProcessEvents) () ; process the event loop
EndSubroutine
;
;===============================================
;
; Private Methods
;
;-----------------------------------------------
;
PrivateSubroutine(DvsML06, Constructor) (ByVal(Me, strDvsML06))
;
; Constructor package class contructor
;
Me\proAppContainer = CreateObject(Container) ; 16085 : ref to the main application container object
EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(DvsML06, Destructor) (ByVal(Me, strDvsML06))
;
; Destructor package class destructor
;
Me\proAppContainer = DestroyObject(Me\proAppContainer) ; 16085 : ref to the main application container object
EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(DvsML06, AppDesign) (ByVal(Me, strDvsML06))
;
; AppDesign design the application window
;
EndSubroutine
;
;===============================================
;
; Virtual Table
;
DataSection
Label(DvsML06, VirtualTable)
;
; primary methods
;
InterfaceFunc(DvsML06, Destroy)
InterfaceFunc(DvsML06, Clone)
;
; external methods
;
InterfaceSubr(DvsML06, Main)
;
EndDataSection
;
;===============================================
; end of : clsDvsML06.pbi
;===============================================
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan