Skip to content

Field_Validate_msg - DataDictionary

Sets the Id of the message to be sent when a table column should be validated

Type: Property
Access: Read/Write
Data Type: Integer
Parameters: None

Parameters

Parameter Type Description
iField Integer Number of the column in the table

Syntax

Property Integer Field_Validate_msg
Access Type Syntax
Read Access: Get Field_Validate_msg to IntegerVariable
Write Access: Set Field_Validate_msg to IntegerVariable/Value

Description

Sets the Id of the message to be sent when a table column should be validated.

Sample

Set Field_Validate_msg Field Employee.PayType to (RefFunc(ValidPayType))

Field_Validate_msg lets you assign a general-purpose message to be sent when a column should be validated. This message will be the message Id of a function and will get called whenever your program requires a validation. This validation method is used when you need to perform complex validations that can only be expressed with code. Since it is a very open-ended process, it can do just about anything.

If the value is valid, the function should return a zero. If the value is invalid, the function should generate an error and return a non-zero value.

This validation method can be used in conjunction with the other validation techniques (checkbox, range, check, validation table) or as a replacement for them.

You must create the validation function(s). This function will get passed the column number and the current column value. Your function may use these values as it sees fit. For this purpose, the value of any other column in the data dictionary may be obtained by getting Field_Current_Value. It is important to note that the validation routine should never need to access a value in a Data Entry Object (DEO). The information required should be found in the DataDictionary Object (DDO) or in one of the DDOs connected to it.

For example, if you have the following member function.

Function ValidateCredit Integer iField Number nValue Returns Boolean
    Boolean bErr
    String sCustRating

    // get the customer rating for this customer from DD buffer
    Get Field_Current_Value Field Customer.Rating to sCustRating

    // if Customer Rating is A1 their limit is 5000
    If ((sCustRating = "A1") and (nValue > 5000)) Begin
        Error DFERR_OPERATOR "Credit limit may not exceed $5000"
        Move True To bErr
    End

    Function_Return bErr
End_Function

To use this function on the Credit_Limit column of a table, you must set the column's validate method (Field_Validate_msg) to the handle name of the function. The handle name of a function is the name of the function called from RefFunc() (e.g., (RefFunc(ValidateCredit)) ). Set Field_Validate_msg column Customer.Credit_Limit to (RefFunc(ValidateCredit)).

You can cancel this validation, for example in a DDO in a dbView, by setting it to No_Confirmation:

Set Field_Validate_msg Field Customer.EMail_Address to (RefFunc(No_Confirmation))

Sample

You can throw an error during validation using Data_Set_Error.

//  Validates if the column contains a valid email address (it allows empty values too).
Function ValidateEmail Integer iColumn String sValue Returns Boolean
    Integer iAt iDot
    Boolean bResult

    If (Trim(sValue) <> "") Begin
        Move (Pos("@", sValue)) to iAt
        Move (RightPos(".", sValue)) to iDot

        If (not(iAt > 1 and iDot > 0 and iDot > iAt + 1 and iDot < Length(sValue))) Begin
            Send Data_Set_Error iColumn DFERR_OPERATOR "Please enter a valid email address"
            Move True to bResult
        End
    End

    Function_Return bResult
End_Function

Syntax

The declaration prototype for a validation method takes the following general form:

Function function_name integer iField type CurrentValue Returns Integer

Where: Function_name is the name of the validation function;iField is the column number of the column that sent function_name. The column number can be used to retrieve any information about the column; and,type and CurrentValue are the data type and current value of the column that sent function_name. This allows you to write generalized validation-method functions that can be re-used for other columns and tables.

See Also

Field_Error | Defining Data Dictionary Field Attributes | RefFunc function