if RecordValid("Client") && validation rules for table "Client" * proceed with save endifThe function itself is saved in stored procedures.
********************************************************************** FUNCTION RecordValid(tcTableName) * Record validation. * Meant to be invoked from form.valid(<tablename>). * Can also be invoked from other places, for instance, triggers. llEvaluateAllRules = .T. tcTableName = lower(tcTableName) * 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 = 2 && Ignore loop endif select (lnOldAlias) if not evaluate(validation.rule) lcErrorText = lcErrorText + iif(validation.level = 1, "Warning: ", "Error: ") + Validation.Message if Validation.level = 0 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, "Can't save:", "Error saving:") + chr(13) + chr(13); + lcErrorText + iif(llError, "", chr(13) + "Changes saved."),; 16, iif(llError, "Error saving", "Warning saving")) endif * restore environment and return success status use in validation select (lnOldAlias) set exact &lcOldExact return not llError ENDFUNC