DelphiBasics
Null
Variable
A variable that has no value Variants unit
  var Null : Variant;
Description
The Null variable has an undefined value.
 
Null does not mean a zero number or empty string - it is undefined. Any expression using a null variable will yield a null result.
 
Null is particularly useful when handling SQL table data - providing a one for one correspondence with the SQL NULL value.
Notes
The Null variable is the Null Variant.

Calculations using nulls yield the EVariantError.
Related commands
Pointer Defines a general use Pointer to any memory based data
Variant A variable type that can hold changing data types
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.


 
Example code : Using Null to represent the result of a bad divide
var
  Answer : Variant;

begin
  Answer := Divide(4,2);

  // Show the result of this division
  if Answer = Null
  then ShowMessage('4 / 2 = Invalid')
  else ShowMessage('4 / 2 = '+IntToStr(Answer));

  Answer := Divide(4,0);

  // Show the result of this division
  if Answer = Null
  then ShowMessage('4 / 0 = Invalid')
  else ShowMessage('4 / 0 = '+IntToStr(Answer));

end;

function TForm1.Divide(Dividend, Divisor: Integer) : Variant;
begin
  // Try to divide the Dividend by the Divisor
  try
    Result := Dividend div Divisor;
  except
    Result := Null ;    // Assign Null if the division threw an error
  end;
end;
Show full unit code
   4 / 2 = 2
   4 / 0 = Invalid
 
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page