Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP 5 Field Rule Violated
Message
 
To
05/07/1998 10:14:51
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00114325
Message ID:
00114458
Views:
16
>How can we determine which field has violated the field rule that wehave set in the database. In VFP 3.0 we could use =AERROR(arrayerr)and arrayerr(3) would give us the name of the field, however in VFP 5( good knows why they have changed it!) we get the Message text! andnot the name of the field, infact =AERROR(), SYS(2018) ... don'treturn the name of the field at all!Further the Tastrade application for VFP 5 uses this to trap fieldrule violation - tsbaseform error routine and the coding there wouldgive us a error. Microsoft have not gone thru there own example codeproperly!

Sonali,

Not far ago I was a strong believer that field rules should be enforced at the .DBC level. When VFP 5 came out, my code had to be enhanced to get around the AERROR() problem. Then I got caught by anoter issue. Take a view with optimistic table buffering. I'm of the opinion that I must be able to add a new field, then anohter, then another without having the field rules pop up in my face "Hey you forgot to put something here", etc.

After some discussions with other fellows Codebook developpers I came to the conclusion that field rules should be enforced at the bizness object level, in a BeforeSave() method. It's just a hook that we have, if BeforeSave() returns .F. there is no Save().
The code has been enhanced to show the user exactly which control needs to be filled (backColor set to flamant red when the message box comes up) and setting the focus to it.

Here are 2 examples of what can be achieved.

Example for a Record buffered view
**********************************
*-- CHANGE - JCM - June 27, 1998 - 18:16:10
*-- Process the field rules here.
LOCAL loSelect, ;
lcField

loSelect = CREATEOBJECT("cSelect", this.cAlias)

lcField = this.cAlias + ".cDojoId"
IF EMPTY( EVAL( lcField))
ThisForm.FindControl( lcField, "Compléter le Dojo...")
RETURN .F.
ENDIF

Example for a table buffered view
*********************************
LOCAL loSelect, ;
lnRetVal, ;
lnNext, ;
lcField, ;
lnOldRec

*-- CHANGE - JCM - June 27, 1998 - 18:16:10
*-- Process the field rules here.
lnRetVal = .T.

loSelect = CREATEOBJECT("cSelect", this.cAlias)
*-- CHANGE - JCM - July 03, 1998 - 18:23:28
*-- Save the record pointer. I've seen cases with uncommitted changes
*-- when saving a newly created parent that had several records added to one child

lnOldRec = RECNO()
lnNext = GETNEXTMODIFIED(0)

SCAN FOR lnNext # 0
lnRetVal = .F.
DO CASE
CASE EMPTY( dStage)
lcField = this.cAlias + ".dStage"
ThisForm.FindControl( lcField, "Compléter la date...")
CASE EMPTY( cLieu)
lcField = this.cAlias + ".cLieu"
ThisForm.FindControl( lcField, "Compléter le lieu...")
CASE EMPTY( cSensei)
lcField = this.cAlias + ".cSensei"
ThisForm.FindControl( lcField, "Compléter le Sensei...")
OTHERWISE
lnRetVal = .T.
ENDCASE
IF ! lnRetval
EXIT
ENDIF
lnNext = GETNEXTMODIFIED(0)
ENDSCAN
GO (lnOldRec)
RETURN lnRetVal

*---------------------- Location Section ----------------------
* Library...........:
* Class.............: Cbaseform
* Method............: FindControl
*-------------------------- Copyright -------------------------
* Author............: Bernhart Milcent
* Project...........: Common
* Created...........: 27/06/98 18:46:54
* Copyright.........: (c) Bernhart Milcent , 1998
*----------------------- Usage Section ------------------------
*) Description.......: Finds a control, set its back color to red
*) : Warn user there is a problem and set back color back
* Scope.............:
* Parameters........:
*$ Usage.............:
*% Example...........:
* Returns...........:
*------------------- Maintenance Section ----------------------
*@ Inputs:...........:
* Outputs...........:
* Pre-condt. invar..:
* Post-condt.invar..:
*? Notes.............: None
* Collab.methods....: None
*--Process...........:
* Change log........:
*--------------------------------------------------------------

LPARAMETERS lcField, lcMessage
LOCAL loObject, ;
lnOldColor

loObject = .NULL.

WITH thisForm
loObject = .FindControlSourceObject( UPPER( lcField))
IF ! ISNULL( loObject)
*-- show it in red
lnOldColor = loObject.BackColor
loObject.BackColor = 255
.ActivateObjectPage( loObject)
loObject.SetFocus()
.REFRESH()
ENDIF
*-- warn usere
errorMsg( lcMessage)
*-- back to the original color
IF ! ISNULL( loObject)
loObject.BackColor = lnOldColor
ENDIF
ENDWITH


The methods FindControlSourceObject and ActivateObjectPage can be found at www.stonefield.com as part of a document describing error handling in VFP.

José
Previous
Reply
Map
View

Click here to load this message in the networking platform