skip to content

Fun Code of the Day #2: Does nil have a type?

/ 1 min read

Okay, no cheating now. That is, no running the code until you’ve guessed.

What is the output of this code?

program Project90;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

  var
    S: TObject;

begin
  try
    S := nil;
    if S is TObject then
    begin
      Writeln('Yup');
    end else
    begin
      Writeln('Nope');
    end;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.

How sure are you?

Now run it and find out. Were you right?

Subscribe to my newsletter

Get things that occur to me delivered straight to your inbox. Totally free, no spam.

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment