Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Default value changes to KBizObj
Message
From
21/05/2001 11:47:55
Rex Mahel
Realm Software, Llc
Ohio, United States
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
The Mere Mortals Framework
Title:
Default value changes to KBizObj
Miscellaneous
Thread ID:
00509507
Message ID:
00509507
Views:
52
Kevin,

Could you make the following changes to KbizObj to allow setting default value in the OnNew method and setting foreign key values in the PreSaveHook method.

Add the following properties:

ADefaultValues[1,2]: An array property that contains default value info for the Business Object's InitialSelectedAlias. Row 1 contains the field name, row 2 contains the expression that sets the value for that field. PostInitHook is a good place to populate this array.

AFKDefaultValues[1,2]:An array property that contains default value info for the Business Object's InitialSelectedAlias. Row 1 contains the field name, row 2 contains the expression that sets the value for that field. PostInitHook is a good place to populate this array.


Add the following methods:

AddDefaultValue():

* Program....: KBizObj.AddDefaultValue
* Version....: 1.0
* Author.....: Rex L. Mahel
* Date.......: February 23, 2001
* Notice.....: Copyright (c) 2001 Realm Software, Inc., All Rights Reserved.
* Compiler...: Visual FoxPro 06.00.8862.00 for Windows
* Abstract...: Populate the aDefaultValue array for later use.
* Changes....:
LPARAMETER tcName, tcExpr
LOCAL ;
lnRows

lnRows = ALEN(This.aDefaultValues,1)

*!*************************************************
*!* If this is not the first view parameter to be
*!* added, add a new row to the array property
*!*************************************************
IF ! EMPTY(This.aDefaultValues[1,1])
lnRows = lnRows + 1
DIMENSION This.aDefaultValues[lnRows,2]
ENDIF

*!*****************************************************
*!* Store the specified valaues in the array property
*!*****************************************************
This.aDefaultValues[lnRows,1] = tcName
This.aDefaultValues[lnRows,2] = tcExpr


SetDefaultValues():

* Program....: KBizObj.SetDefaultValues
* Version....: 1.0
* Author.....: Rex L. Mahel
* Date.......: February 23, 2001
* Notice.....: Copyright (c) 2001 Realm Software, Inc., All Rights Reserved.
* Compiler...: Visual FoxPro 06.00.8862.00 for Windows
* Abstract...: Populate new record fields with values from supplied expression.
* Changes....:
IF ! This.HasDefaultValues()
RETURN
ENDIF

LOCAL ;
loSelect,;
lcField,;
lcExpr,;
lcFieldState

loSelect = This.SelectAlias()

*-------------------------------------
*--- Set all default values (if any)
*-------------------------------------
FOR lnCount = 1 TO ALEN(This.aDefaultValues,1)
lcField = This.aDefaultValues[lnCount,1]
lcExpr = This.aDefaultValues[lnCount,2]
REPLACE (lcField) WITH &lcExpr
ENDFOR


HasDefaultValues():
* Program....: RKBizObj.HasDefaultValues
* Version....: 1.0
* Author.....: Rex L. Mahel
* Date.......: February 26, 2001
* Notice.....: Copyright (c) 2001 Realm Software, Inc., All Rights Reserved.
* Compiler...: Visual FoxPro 06.00.8862.00 for Windows
* Abstract...: Does this business object have any default values defined?
* Changes....:
RETURN ! EMPTY(This.aDefaultValues[1,1])


SetDefaultValueState():
* Program....: RKBizObj.SetDefaultValueState
* Version....: 1.0
* Author.....: Rex L. Mahel
* Date.......: February 23, 2001
* Notice.....: Copyright (c) 2001 Realm Software, Inc., All Rights Reserved.
* Compiler...: Visual FoxPro 06.00.8862.00 for Windows
* Abstract...: Sets the default value field's state so they will be saved to the base table
* Changes....:
IF ! This.HasDefaultValues()
RETURN
ENDIF

LOCAL ;
llTableBuffered,;
liCount,;
lcField

llTableBuffered = INLIST(CURSORGETPROP('Buffering'),DB_BUFLOCKTABLE,DB_BUFOPTTABLE)

*-----------------------------------
*--- Set all default field states
*-----------------------------------
FOR liCount = 1 TO ALEN(This.aDefaultValues,1)
lcField = This.aDefaultValues[liCount,1]
IF llTableBuffered
SCAN
IF IsAdding(ALIAS())
This.SetFldState(lcField)
ENDIF
ENDSCAN
ELSE
IF IsAdding(ALIAS())
This.SetFldState(lcField)
ENDIF
ENDIF
ENDFOR




AddFKDefaultValue():

* Program....: KBizObj.AddDefaultValue
* Version....: 1.0
* Author.....: Rex L. Mahel
* Date.......: February 23, 2001
* Notice.....: Copyright (c) 2001 Realm Software, Inc., All Rights Reserved.
* Compiler...: Visual FoxPro 06.00.8862.00 for Windows
* Abstract...: Adds foreign key default values for later replacement
* Changes....:
LPARAMETER tcName, tcExpr
LOCAL ;
lnRows

lnRows = ALEN(This.aFKDefaultValues,1)

*!*************************************************
*!* If this is not the first view parameter to be
*!* added, add a new row to the array property
*!*************************************************
IF ! EMPTY(This.aFKDefaultValues[1,1])
lnRows = lnRows + 1
DIMENSION This.aFKDefaultValues[lnRows,2]
ENDIF

*!*****************************************************
*!* Store the specified valaues in the array property
*!*****************************************************
This.aFKDefaultValues[lnRows,1] = tcName
This.aFKDefaultValues[lnRows,2] = tcExpr








SetFKDefault():

* Program....: KBizObj.SetFKDefault
* Version....: 1.0
* Author.....: Rex L. Mahel
* Date.......: February 23, 2001
* Notice.....: Copyright (c) 2001 Realm Software, Inc., All Rights Reserved.
* Compiler...: Visual FoxPro 06.00.8862.00 for Windows
* Abstract...: Populates the foreign key default fields from the aFKDefault array
* Changes....:
IF ! This.HasFKDefault()
RETURN
ENDIF

LOCAL ;
lnCount,;
lcField,;
lcExpr,;
liGetFldState

*-----------------------------------------
*--- Set all foreign key values (if any)
*-----------------------------------------
llTableBuffered = INLIST(CURSORGETPROP('Buffering'),DB_BUFLOCKTABLE,DB_BUFOPTTABLE)

*-------------------------------------
*--- Set all foreign key values (if any)
*-------------------------------------
FOR lnCount = 1 TO ALEN(This.aFKDefaultValues,1)
lcField = This.aFKDefaultValues[lnCount,1]
lcExpr = This.aFKDefaultValues[lnCount,2]
IF llTableBuffered
SCAN
IF IsAdding(ALIAS())
REPLACE (lcField) WITH &lcExpr
ENDIF
ENDSCAN
GO TOP
ELSE
IF IsAdding(ALIAS())
REPLACE (lcField) WITH &lcExpr
ENDIF
ENDIF
ENDFOR


HasFKDefault()

* Program....: KBizObj.HasFKDefault
* Version....: 1.0
* Author.....: Rex L. Mahel
* Date.......: February 27, 2001
* Notice.....: Copyright (c) 2001 Realm Software, Inc., All Rights Reserved.
* Compiler...: Visual FoxPro 06.00.8961.00 for Windows
* Abstract...: Does this business object have any foreign keys defined?
* Changes....:
RETURN ! EMPTY(This.aFKDefaultValues[1,1])


SetFldState():
* Program....: RkBizObj.SetFldState
* Version....: 1.0
* Author.....: Rex L. Mahel
* Date.......: February 28, 2001
* Notice.....: Copyright (c) 2001 Realm Software, Inc., All Rights Reserved.
* Compiler...: Visual FoxPro 06.00.8961.00 for Windows
* Abstract...: Sets the field state for the given field
* Changes....:
LPARAMETER tcField

LOCAL ;
lcFieldState,;
lcFieldStateD

lcFieldState = GETFLDSTATE(tcField)
lcFieldStateD = ;
IIF(INLIST(lcFieldState,2,4),lcFieldState,;
IIF(lcFieldState = 1,2,4))

SETFLDSTATE(tcField,lcFieldStateD)


Note that SetDefaultValueState is not being used. It changes the state of the given field after the value is changed, so if the user presses ESCAPE, the edit will stop without an “Are you wure?” message.

I subclassed my KbizObj class first and added the above, but I want the functionality in such objects as KmoverObj and other Kevin created objects.

Thanks

Rex
Next
Reply
Map
View

Click here to load this message in the networking platform