- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


Frequently Asked Questions

Checking for NULL in OnUpdateData handler

Question:

How can I tell if a user has changed a string field to null in the OnUpdateData event handler? How can I differentiate between a field that was changed to a null string and a field that was not changed at all.

Answer:

Use the NewValue property on the TField when reading the

second record (the one which contains the edits).  If the 

returned variant is empty (or Unassigned) then that field

was not modified. Here is some code that demonstrates this:



   var

     NewVal: Variant;

   begin

     NewVal := DataSet.FieldByName('MyStrField').NewValue;

     if VarIsEmpty(NewVal) then

        ShowMessage('Field was not edited')

     else if VarIsNull(NewVal) then

        ShowMessage('Field was blanked out')

     else

        ShowMessage('New Field Value: ' + String(NewVal));

   end;



If you look at the source for the RecError form (in the 

repository), you will see how it uses this information to 

display the '<Unchanged>' string when showing the reconcile 

errors.  On the server you add record level constraints

using the constraints property of your TQuery/TTable or

field level constraints using persistent TField objects

(either CustomConstraint or ImportedConstraint).  If you use

field level constraints, they are enforced when data is

posted to the field (i.e. when you tab out of a data aware

control associated with the field).




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile