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

Posted by on in Blogs

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?

Original author: This email address is being protected from spambots. You need JavaScript enabled to view it.

Gold User, Rank: 51, Points: 45
I'm a Delphi developer and a Senior Developer at Gateway Ticketing.


Check out more tips and tricks in this development video: