tags:

views:

192

answers:

1

I have an Aggregate field in a client data set and I use a function to get the aggregate value, if the client data set is empty the function should return 0.

if I do this:

if MyClientDataSet.AggregateField.IsNull then
   Result := 0
else
   Result := MyClientDataSet.AggregateField.Value;

when the client data set is empty the else part is executed and raise an exception (cannot convert Variant to Currency error).

But if I do it this way

if MyClientDataSet.AggregateField.Value = Null then
   Result := 0
else
   Result := MyClientDataSet.AggregateField.Value;

it works fine!

So my question is: What's the difference between the IsNull property and comparing the Value property with the Null Value, In a TAggregateField?

+2  A: 

When you have no record (dataset empty) you don't have a field for which the value would be null (reading from the record buffer), so the IsNull function of the Field returns false.
In the other case you test that you have a null variant which is what the dataset returns in GetAggregateValue.

François