Returns true if a reference is not nil System unit
1  function Assigned ( PointerName : Pointer ) : Boolean;
2  function Assigned ( ObjectName   : TObject ) : Boolean;
3  function Assigned ( MethodName   : Method ) : Boolean;
The Assigned function checks to see if a reference is not nil. It returns True if not nil, and False if nil.
Use of a Nil reference will result in an exception.
The three versions of Assigned allow the function to work on data pointers, object references, and class method references.
It is better to use Assigned rather than Nil when referring to methods so as to distinguish from the checking of a nil result of a method.
Related commands
Nil A pointer value that is defined as undetermined
Pointer Defines a general use Pointer to any memory based data
 Author links

 Buy Website Traffic at

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

Example code : A simple example
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
unit Unit1;
  // The System unit does not need to be defined
  Forms, Dialogs;
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
Form1: TForm1;
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);

  myPtr : PChar;

  // Pointer variables are not set to nil by default
  if Assigned(myPtr)
  then ShowMessage('myPtr is not nil')
  else ShowMessage('myPtr is nil');

  // So we must set them to nil to be sure that they are undefined
  myPtr := Nil;
  if Assigned(myPtr)
  then ShowMessage('myPtr is still not nil')
  else ShowMessage('myPtr is nil');
Hide full unit code
   myPtr is not nil
   myPtr is nil
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page