Appearance
Testing for Null etc
Testing for Null / empty / blank values
Data values in Flow can be:
- fields in Source, Destination, or custom datasets (see TField Class)
- special variables, such as Super Globals (see Super Globals)
- user-declared variables (see Variables)
Each data value will be of a particular Data Type, and it is important that the relationship between values and Types is understood so that Flow can be configured correctly. Information about each value/Type relationship is available from the links listed above. The purpose of this page is to explain how to test for Null, empty, and/or blank values across various Data Types.
The simple data types, such as string, integer, double, and boolean, will always have a non-null value.
A string variable is "empty" when it contains no character, i.e. it has a length of zero characters (see Length function). A string variable is "blank" when it contains one or more space characters, and nothing else. A blank string can be forced to be an empty string by using the Trim function (see Trim). A string variable cannot be "null".
An integer or double variable has a default value of 0. An integer or double variable cannot be "null". A boolean variable has a default value of False, and cannot be "null".
Flow makes a lot of use of variables of Type Variant (see Variant).
Each Variant variable will have a "variant type" - essentially a sub-type.
A Variant variable will have a default Variant Type of Null.
The Variant Type of a Variant variable will change when a value is assigned to the variable, and the Type will be derived from the value that is assigned.
- If an empty string is assigned to a Variant, then its Variant Type will be "string".
The simplest way to test a Variant for a Null value (and/or Null sub-type) is to use the VarIsNull function (see example below).
A field in a dataset is a more sophisticated type of variable - an "object" - which includes some built-in type-conversion routines.
The Value property of a dataset field object returns the data value of that field as a Variant.
- It can be of Variant Type Null if the underlying database value is Null.
- It will be of Variant Type String if the underlying database column is a string type (e.g. varchar) and a string value (including an empty string) has been assigned to that column in that row in the database.
- It will be of Variant Type Integer if the underlying database column is an integer type (e.g. int) and a value has been assigned to that column in that row in the database.
The data value contained within the field object can be forced to a particular data type by using the .AsString, .AsInteger, and .AsFloat properties of the field object.
Examples:
pascal
procedure ScriptEvent (var Value : variant)
var myVariant : variant;
myString: string;
myInteger: integer;
begin
myVariant := SOME_DATAVIEW['Any_Field'].Value; // .Value returns a Variant
if VarIsNull(SOME_DATAVIEW['Any_Field'].Value) then
LogInfo('Any_Field has a Null value');
myString := SOME_DATAVIEW['Any_Field'].AsString; // .AsString forces conversion to a string type
if Trim(SOME_DATAVIEW['Any_Field'].AsString) = '' then // Note: using .AsString and the Trim function
LogInfo('Any_Field is either Null, an empty string, or a string of one or more spaces');
if SOME_DATAVIEW['Any_Field'].AsInteger = 0 then
LogInfo('Any_Field is either Null, or zero'); // but .AsInteger will fail if value is neither Null nor numeric
end