Monday, September 10, 2007

Subclassing SL in Visual DataFlex

Hi, while others would think it strange to hear, I have just programmed my first global variable ever and am happy with my decision! As many know, Applause Software is a North American Mfg's rep for Soft Sys which is currently negotiating a VDF 12.1 release of it's proven VDF7 verticle market product named "MASS" (Membership Administration Software Solution). This work is for that project. Much of the code design involves making all instances of a GUI standardized and centralized in coding technique.

Ref: http://www.membershipadmin.com/
Ref: Peter Brooks @ SoftSys: Info@MembershipAdmin.Com

In keeping with my best oops foundation, I have never ever coded a global variable until now. I always used client area properties to communicate between views etc.

The premise:
How to program a selection list or popup dialog to say whether the user pressed OK or not.

Many decisions, especially in views and reportviews need to know if the user changed the value in the dbform or form. Usage of onchange needs to be programmed into each and every dbform or form if this is desired, getting the value prior to forward sending prompt and getting the value after forward sending prompt. Very messy that way.

So:
My global variable is necessary because:
It's programmed into the classes which will be precompiled prior to the client area existing.
Since it's a SL value, each and every dbmodal panel would have to be non-deferred-create if the panel carried the property.

Explanation of this:
Procedure Prompt
Boolean bOk
Set pbOk of (prompt_object(self)) to false // doesn't exist yet! // error!
Forward Send Prompt
Get pbOk of (prompt_object(self)) to bOk // dialog has been destroyed // error!
End_Procedure

The gv: // [global variable]

Boolean gbOK
Contained in the TOP of the custom classes use package.
This way, if the classes are used in another program, you don't have to code the gv again.
My classes for Soft Sys based on the dbModalPanel: (special subclass for selection lists).

//============================================//
Class cSoftSysDbModalPanel is a dbModalPanel
Procedure Construct_Object
Forward Send Construct_Object
// Define new Properties:
Property Boolean pbSelectionList Public False
// Create child objects:
// Set property values:
End_Procedure

Procedure End_Construct_Object
Forward Send End_Construct_Object
// Add your code that needs to be executed at the end of the object construction here:
// This overrides the individual object settings as existed in VDF7
If (not(pbSelectionList(Self))) Set Border_Style to Border_Dialog
Else Set Border_Style to Border_Thick
End_Procedure
// Create and augment procedures and functions
Procedure Popup
Move False to gbOk
Forward Send Popup
End_Procedure
Procedure Set Label String sMyLabel
// intercepts the setting of the label, and does a language [australian to usa] translation!
Integer iPos1 iPos2
If (sMyLabel > "") Begin
If (CurrentCountry(Self) = "United States") Begin
POS "Enrol" in sMyLabel to iPOS1
POS "Enroll" in sMyLabel to iPOS2
If (iPOS1 <> iPOS2) Replace "Enrol" in sMyLabel With "Enroll"
POS "enrol" in sMyLabel to iPOS1
POS "enroll" in sMyLabel to iPOS2
If (iPOS1 <> iPOS2) Replace "enrol" in sMyLabel With "Enroll"
End
Forward Set Label to sMyLabel
End
End_Procedure
// Automatic Save_Header for dbgrids etc. built into dbView-dbModalPanel.
Function DoSaveHeader Returns Boolean
Send Request_Save_No_Clear
If (Should_Save(Server(Self))) Function_Return True
If (IsNullRowID(CurrentRowID(Server(Self)))) Begin
Error DFErr_Operator "Please Enter Info In Top Part Of Entry Form"
End
If (Err) Function_Return True
Function_Return False
End_Function
// Note: See individual topic in previous post for this function!
End_Class
//============================================//
// Note: with search and replace, I replaced the class of all SL panels with this one:
Class cSoftSysDbModalPanelSL is a cSoftSysdbModalPanel
Procedure Construct_Object
Forward Send Construct_Object
// Define new Properties:
// Create child objects:
// Set property values:
Set pbSelectionList to True
End_Procedure
Procedure End_Construct_Object
Forward Send End_Construct_Object
// Add your code that needs to be executed at the end of the object construction here:
End_Procedure
// Create and augment procedures and functions
End_Class
//============================================//
// Note: with search and replace, I replaced all instances of dbLists with this class:
Class cSoftSysDbList is a dbList
Procedure Construct_Object
Forward Send Construct_Object
// Define new Properties:
// Create child objects:
// Set property values:
Send DoDefineShadowedColorUpgradeProperties
End_Procedure

Import_Class_Protocol cSoftSysShadowedColorUpgrade

Procedure End_Construct_Object
Forward Send End_Construct_Object
// Add your code that needs to be executed at the end of the object construction here:
// These setting OVERRIDE the object settings whatever they may be!
// Makes previously coded stuff all uniform now.
Set CurrentRowColor to clYellow
Set GridLine_Mode to Grid_Visible_Both
Set peAnchors to anAll
End_Procedure
Procedure Set Header_Label Integer iColumn String sText
// Another interception of setting the label for a language translation...
If System.Label_Surname gt "" Replace "Surname" in sText with (Trim(System.Label_Surname))
Else If (CurrentCountry(Self) = "United States") Replace "Surname" in sText with "Last Name:"
Forward Set Header_Label item iColumn to sText
End_Procedure
// Create and augment procedures and functions
Procedure Ok
If (Move_Value_Out_State(Self)) Move True to gbOk
Forward Send Ok
End_Procedure
End_Class
//============================================//

So now, in effect, what I am doing with the global variable is setting it to false on popup and setting it to true upon clicking the OK button of the SL or pressing enter to select a record in the SL.

Because it's a global variable, it can be coded into the classes which are precompiled prior to the client area (on the desktop) and referred to in class code prior to the oApplication being executed to open the workspace etc.

End Result in Code: // if you need to know whether the user is getting a variable from the SL:

Object oMyForm is a cSoftSysForm // non data aware such as in a report.
Procedure Prompt
Forward Send Prompt
If (gbOk) Begin
// do whatever you need to do with the value like setting a property to govern the constraints or output options.
End
End_Procedure

//===================================//
End Article!
PAD

No comments: