Jump to content

Function IsNull returns wrong value


TSeba

Recommended Posts

Hi:

 

I have the following problem when trying to validate the data of a record in an Interbase table. At the time of the Post, valid if one of the fields you are entering is Null or less than 0 (zero). I evaluate if it is null using the IsNull function, the problem that if you enter 0 (zero) in the registry the IsNull function returns False when it should be True.

I've already tried using the Permanent Field format or using the FielbByName function and the result is the same.

It is important to add that the 0 can be a valid value, not the Null value.

I am working with Delphi Tokyo and Unigui version 1.10.0.1471.

Any idea how to fix this?.

 

Thanks in advance for your help

Link to comment
Share on other sites

Hi,

I am using a UniDbGrid that is related to an Interbase table. The UniDbGrid columns show the information of the fields in the table. When inserting a record in that grid and before inserting itself into the interbase table, a series of validations is made, one of those validations is that a field (In this case, Amount From) can be loaded amounts greater than or equal to 0 and is correct. These validations are executed before registering the record in the table

 

If TableName.FieldByName ('AmountFrom'). IsNull then

  ShowMessage ("You must enter an amount greater than or equal to 0")

 

The problem is that if I charge amount = 0 the, when doing the previous validation I get the message that I must enter an amount because the IsNull function returns TRUE. This is not correct since the field has the value 0 and therefore is not null. If 0.01 is reported (or any value other than 0) the message does not appear because the IsNull function returns FALSE.

 

In this case I am not using querys but I use the TIBCTable and TIBCDataSource components.

 

I hope it was clearer.

 

Thank you

Link to comment
Share on other sites

On the DB level there is always differentiation between NULL and 0.

 

But the .IsNull function obviously does not work that way.

 

What if you try,

If length(TableName.FieldByName('AmountFrom').AsString)=0 then
  ShowMessage ("You must enter an amount greater than or equal to 0")

Then you only check for NULL (no value) and not 0.

Link to comment
Share on other sites

maybe you are validating this in the wrong place, and at this point the query still has the null value, has not received the value yet, tried to do this in the field validate directly in the query? or in query beforepost. if even in these events this does not work, for sure and bug in your component query, why not use firedac? besides native it has excellent support for interbase firebird

Link to comment
Share on other sites

On the DB level there is always differentiation between NULL and 0.

 

But the .IsNull function obviously does not work that way.

 

What if you try,

If length(TableName.FieldByName('AmountFrom').AsString)=0 then
  ShowMessage ("You must enter an amount greater than or equal to 0")

Then you only check for NULL (no value) and not 0.

 

Thanks for the answer but this does not work for me because if it has the value 0 loaded the length of the field is 0 and it really is not. Obviously this is a problem of the components of Devart that I am using. I'm going to have to consult them. Thanks again

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...