Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Field Level Error Message
Message
From
31/05/2004 11:36:24
Mike Sue-Ping
Cambridge, Ontario, Canada
 
 
To
31/05/2004 11:18:24
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00906987
Message ID:
00908668
Views:
17
Hilmar,

The response outlining your design to handle validation looks very interesting. I was wondering if you would be willing to share more of it by putting together a small demo. You know what they say, "A picture is worth a thousand words".

Regards,

Mike


>I would suggest a redesign in two areas.
>
>First, you would usually not show the end-user a BROWSE window. A Grid on a form offers you much more flexibility.
>
>Second, I personally dislike validation rules, both at the field-level, and at the record-level. The main reason is that both may get evaluated too early, when you can't control it.
>
>A trigger, on the other hand, gets evaluated only when you try a TableUpdate(). (I am assuming that you use buffering, of course.)
>
>Personally, I do most validation through rules stored in a table. Here is my function, which I call when the user tries to save a record:
>
>
>FUNCTION RecordValid(tcTableName, llEvaluateAllRules)
>	* Record validation.
>	* Meant to be invoked from form.valid(tablename).
>	* Can also be invoked from other places, for instance, triggers.
>
>	tcTableName = lower(tcTableName)
>	llEvaluateAllRules = .T.  && Override second parameter.
>
>	* save and change settings
>	local lnOldAlias, lcOldExact
>	lnOldAlias = select()
>	lcOldExact = set("exact")
>	set exact off
>
>	* open validation table
>	if used("validation")
>		select validation
>	else
>		select 0
>		use validation again
>	endif
>	set order to "mainorder"
>
>	* evaluate all errors defined in rules table
>	local lcErrorText, llError
>	lcErrorText = ""
>	tcTableName = padr(tcTableName, len(Table))
>	seek tcTableName
>	scan while table = tcTableName
>		if Level = "I" && Ignore
>			loop
>		endif
>		select (lnOldAlias)
>		if not evaluate(validation.rule)
>			lcErrorText = lcErrorText + iif(Validation.Level = "W", "Advertencia: ", "Error: ") + Validation.Spanish
>			if not Validation.Level = "W"
>				llError = .T.
>			endif
>			if llEvaluateAllRules
>				lcErrorText = lcErrorText + chr(13)
>			else
>				exit
>			endif
>		endif
>		select validation
>	endscan
>
>	* show error message
>	if not empty(lcErrorText)
>		MessageBox(iif(llError, "No se pudo guardar:", "Advertencia al guardar:") + chr(13) + chr(13);
>			+ lcErrorText + iif(llError, "", chr(13) + "Se guardaron los cambios."),;
>			16, iif(llError, "Error al guardar", "Advertencia al guardar"))
>		*MessageBox(iif(llError, "Can't save:", "Warning on save:") + chr(13) + chr(13);
>		*	+ lcErrorText + iif(llError, "", chr(13) + "Changes saved."),;
>		*	16, iif(llError, "Error on save", "Warning on save"))
>	endif
>
>	* restore environment and return success status
>	use in validation
>	select (lnOldAlias)
>	set exact &lcOldExact
>	return not llError
>ENDFUNC
>
>
>And this is the corresponding table structure:
>
>
>Field  Field Name      Type                Width    Dec   Index   Collate Nulls
>    1  TABLE           Character              30            Asc   Machine    No
>    2  ORDER           Integer                 4            Asc   Machine    No
>    3  RULE            Memo                    4                             No
>    4  SPANISH         Memo                    4                             No
>    5  COMMENTS        Memo                    4                             No
>    6  WARNING         Logical                 1                             No
>    7  LEVEL           Character               1                             No
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform