skip to content
Nick Hodges Nick Hodges

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.

Powered by Respectify

Comments are analyzed in real time for spam and respectfulness before they appear. Leave a comment to see Respectify in action.

Try the demo →

Comments ()

Loading comments…

No comments yet. Be the first to comment!

Leave a Comment

Your comment will be reviewed by Respectify before it appears.