Extending what Craig stated, I played around with a table's
record validation rules and came up with the code below.
It's not generic yet, but should be fairly easy to make
the needed changes to make it generic
It works propertly except for the condition described below.(*** Where it fails ***)
Unfortunately, it uses public variables that get defined
inside of the function which of course lend themselves to
maintenance problems.
*** Where it fails ***
If !b_lSend && Maintenance code has send the record to archive
Return .t.
Endif
Not sure yet how to get around the above.
The assumption is that whatever maintenance program exits
will send all records with lSend equal to True offsite and
after doing so will set lSend to False.
The problem arises when an existing record that has been sent to offsite archiving is updated later.
Since the field lSend will then be False, it doesn't get updated by the stored procedure.
Maybe another field can be added that is included in the test. I'll play a little more later.
Just a start.
Darrell
Code:
* I created a table in a DBC called test which has two fields:
* lSend b, Field1 c(10)
* In the default value for the field lSend, I placed .T.
* and in the table's record validation rule I placed the following:
* SetDefault(lsend,RECNO())
* In the stored procedures I created the following function:
Function SetDefault(b_lSend,nRecNo)
* Note: This is a hack and probably doesn't need to be
* this complicated :-)
If !b_lSend && Maintenance code has send the record to archive
Return .t.
Endif
If type("gaValidated")=="U"
Public array gaValidated[1]
gaValidated[1] = 0
Public gnValidated
gnValidated = 0
Endif
Local nValidatedRec, bAtZero
nValidatedRec = ascan(gaValidated,nRecNo)
If nValidatedRec == 0
gnValidated = gnValidated + 1
Dime gaValidated[gnValidated]
gaValidated[gnValidated] = nRecNo
Replace lSend with .t.
Else
=Adel(gaValidated,nValidatedRec)
gnValidated = gnValidated -1
If gnValidated == 0
gnValidated = 1
bAtZero = .t.
Endif
Dime gaValidated[gnValidated]
If bAtZero
gaValidated[gnValidated] = 0
Endif
Endif
Return .t.
Endfunc