Introduction
Xbase++ is a development tool that offers Xbase Parts for building Windows Desktop applications. One feature that Xbase++ programmers can leverage is the ability to configure these Xbase Parts through subclassing. Not only does this approach allow for personalized coloring and UI behavior for each individual instance, but it also simplifies behavior modifications by centralizing them in one place. In this article, we will explore how Xbase Parts can be configured by subclasses and demonstrate how to implement identical behavior using a subclass of XbpStatic.Configuring Xbase Parts with Individual Instances
To illustrate the configuration of Xbase Parts with individual instances, let's consider an example using the XbpStatic class. The following code snippet demonstrates how to configure an XbpStatic instance by customizing its coloring and UI behavior to become a label on an XbpDialog instance:
Xbase++:
...
oXbp := XbpStatic():new( oDrawingArea, , {276,216}, {84,24}, { { XBP_PP_BGCLR, GRA_CLR_GREEN }, { XBP_PP_FGCLR, GRA_CLR_BLUE } } )
oXbp:caption := "Text"
oXbp:clipSiblings := .T.
oXbp:options := XBPSTATIC_TEXT_VCENTER+XBPSTATIC_TEXT_RIGHT
oXbp:create()
...
Behavior Modifications through Subclassing
Instead of configuring each instance individually, we would instead like to just adjust the position and size in our code. Everything else is to be taken over by a derived class MyLabel:
Xbase++:
...
oXbp := MyLabel():new( oDrawingArea, , {276,216}, {84,24} )
oXbp:caption := "Text"
oXbp:create()
...
Xbase++:
CLASS MyLabel FROM XbpStatic
EXPORTED:
METHOD init
METHOD create
ENDCLASS
METHOD MyLabel:init( oP, oO, oPos, aSize, aPP, lVisible )
aPP := ChangePresParam( aPP, { XBP_PP_BGCLR, GRA_CLR_GREEN } )
aPP := ChangePresParam( aPP, { XBP_PP_FGCLR, GRA_CLR_BLUE } )
SUPER:init( oP, oO, oPos, aSize, aPP, lVisible )
RETURN SELF
METHOD MyLabel:create()
::clipSiblings := .T.
::options := XBPSTATIC_TEXT_VCENTER+XBPSTATIC_TEXT_RIGHT
SUPER
RETURN SELF
To manipulate the array of presentation parameters we use the auxiliary function ChangePresParam:
Xbase++:
FUNCTION ChangePresParam( aPP, aNew )
LOCAL nPos
aPP := Coalesce( aPP, Array(0) )
nPos := AScan( aPP, {|e| e[1] == aNew[1] } )
IF nPos > 0
aPP[nPos,2] := aNew[2]
RETURN aPP
ENDIF
AAdd( aPP, aNew )
RETURN aPP