128 ObjectPAL: Event model
VERSIONS: Paradox 5 and later

SUBJECT: error information lost

BY: BERTIL ISBERG
Date: 25 January 2005

A required validity check will tell you which field is in error if you try to unlock a record where a required field value is missing. You'll get an error "Field value required." followed by Fieldname: Your field.

You have a single table form with a tableframe or a MRO showing the data. You add some simple code to your form to get a handle to the currently active field. The code goes into the form level arrive method
var
   uiFld,
   uiTarget       UIObject
endvar

if eventInfo.isPrefilter() then
   eventInfo.getTarget(uiTarget)
   if uiTarget.Class = "Field"  then
      uiFld.attach(uiTarget)
   endif
else
endif
Note: the uiFld should in a real world example be declared in form level VAR window to be available to other methods.

Your code will cause Paradox to loose track on which field is in error in the Required valcheck. All you get is a Field value required error.

The line of code responsible for this side effect is uiFld.attach(uiTarget). Why?
The required error is caused by unlockrecord which is caused by a nextrecord. The event chain for a nextrecord is so complex, I'll avoid showing it all. But as unlockrecord is caused by a request to leave a record, it is naturally followed by arrival to a field in next record. So form level arrive event will execute even though next record has been prevented and even though there is a pending error when arrive executes. This can be seen by inserting
if errorcode()=peOk then
after if eventInfo.isPrefilter()

So the loss of error information is caused by code executing after the error has occured; code that partly clears the errorstack, in this case uiFld.attach(uiTarget). One solution to the problem in this case is to NOT execute the code in arrive event when an error has occurred.
var
   uiFld,
   uiTarget       UIObject
endvar

if eventInfo.isPrefilter() then
   if errorcode()=peOk then
      eventInfo.getTarget(uiTarget)
      if uiTarget.Class = "Field"  then
         uiFld.attach(uiTarget)
      endif
   endif
else
endif

To index