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 ENDFUNCAnd 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