Board index » delphi » Checking if Datafields of type string are empty??

Checking if Datafields of type string are empty??

Hello!

I found out, than this code causes av's later in the app, especially when
closing it.

procedure TAuftragForm.AufReTableFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
  If TTable(DataSet).Active then
    Accept := (TTable(DataSet).FieldByName('LS_DT').AsString <> '') and
(TTable(DataSet).FieldByName('R_NR').AsString = '')
end;

Changing "...AsString <>/= ''" to "...AsString <>/= NULL" seems to remove
the problem.

But is this sure? And why does Delphi behave this way??

Thanks for your help,
Andreas Vo?loh

 

Re:Checking if Datafields of type string are empty??


FieldByName returns a variant with the value of the field, and you can
check it with IsNull, irrespective of the type of field. So I would
suggest using:

Accept:= (Not TTable(DataSet).FieldByName('LS_DT').IsNull) And (Not
TTable(DataSet).FieldByName('R_NR').IsNull);

Manuel Algora
m...@encomix.es

Re:Checking if Datafields of type string are empty??


Ahh, thats smart... Thanks

 So I would

Quote
> suggest using:

> Accept:= (Not TTable(DataSet).FieldByName('LS_DT').IsNull) And (Not
> TTable(DataSet).FieldByName('R_NR').IsNull);

Other Threads