Conditionally Validate a dbf index key value as UNIQUE
──────────────────────────────────────────────────────────────────────────────
Syntax
IsKeyValid( <xKey>, <nMode>, <cAlias>, ;
<bLookup>, <bAssign> ) -> lOk
Arguments:
<cKey> is a valid key value for the current index.
<nMode> is a manifest constant to conditionally validate the key
<cAlias> is the file alias to validate against
<bLookup> is a code block to display a lookup/picklist
<bAssign> is a codeblock to assign fields to variables
Returns:
A logical value, .T. if the key is conditionally valid
Description:
GT_ISKEYVALID() can be used to validate a get against an indexed file,
to ensure a UNIQUE key value.
to validate a new record as UNIQUE,
to validate an edit of an existing record as UNIQUE,
optionally providing a picklist codeblock on failure,
optionally providing an additional assign codeblock on success.
Examples:
#define NEWRECORD 1
#define DISPEDIT 2
#define DISPONLY 3
#define LOOKUP 4
************************
PROCEDURE test()
cVatId := " "
nVat := 0.0
FirstGet( NEWRECORD )
READ
SecondGet( LOOKUP )
READ
RETURN
*************************
function FirstGet( nMode )
@ 08, 20 SAY "Input a New VAT Code : " GET cVatId PICTURE "@K!" ;
VALID ISKEYVALID( cVatId, nMode ) ;
when ( nMode == NEWRECORD )
**************************
function SecondGet( nMode )
@ 10, 20 SAY "Input current VAT Code : " GET cVatId PICTURE "@K!" ;
VALID ISKEYVALID( cVatId, LOOKUP, "VAT", ;
{|| vat( @cVatId, @nVat ) }, ;
{ || nVat := vat->Vat } )
@ 11, 20 GET nVat PICTURE "99999.99" when ( .F. )
return ( NIL )
***************************
where : {|| vat( @cVatId, @nVat ) }
is a codeblock calling a picklist which can assign variables
passed by reference.
and : { || nVat := vat->Vat } )
is a codeblock which will assign ALIAS->FIELD to the
looked up variable refered to.
Source: GT_VALID.PRG
Author: George Brennan