{"id":168,"date":"2007-09-03T15:55:27","date_gmt":"2007-09-03T05:55:27","guid":{"rendered":"http:\/\/www.malcolmgroves.com\/blog\/?p=168"},"modified":"2013-09-12T21:52:49","modified_gmt":"2013-09-12T11:52:49","slug":"nullable-types-in-delphi","status":"publish","type":"post","link":"http:\/\/www.malcolmgroves.com\/blog\/?p=168","title":{"rendered":"Nullable Types in Delphi"},"content":{"rendered":"<p>I was traveling a bunch over the last two weeks, USA, Japan and Korea. In Osaka, I did a session on Generics for the <a href=\"http:\/\/dn.codegear.com\/jp\/article\/36889\/\">Japan Developer Camp<\/a>.<\/p>\n<p>Afterwards, I was having a further play with <a href=\"http:\/\/dn.codegear.com\/article\/36620#4DelphiHighlander\">Highlander<\/a> and Generics and stumbled across something rather nice. Maybe everyone else is aware of this already, but the new Generics support in Delphi for .NET also gives us access to Nullable types. So the following code:<\/p>\n<pre><code>var<\/code><br \/>  MyInt : Nullable&lt;Integer&gt;;<br \/><code>begin<\/code><br \/>  Listbox1.Items.Add(MyInt.HasValue.ToString); <br \/>  MyInt := 18;<br \/>  Listbox1.Items.Add(MyInt.HasValue.ToString);<br \/>  Listbox1.Items.Add(MyInt.Value.ToString);<br \/><code>end<\/code>;<\/pre>\n<p>produces the following output in the Listbox:<\/p>\n<p>false<\/p>\n<p>true<\/p>\n<p>18<\/p>\n<p>I&#8217;m currently reading through <a href=\"http:\/\/www.amazon.com\/Professional-NET-2-0-Generics-Programmer\/dp\/0764559885\/ref=pd_bbs_sr_1\/105-2555916-9622007?ie=UTF8&amp;s=books&amp;qid=1188871070&amp;sr=8-1\">Professional .NET 2.0 Generics<\/a> to get a better understanding of all the possibilities, but already I&#8217;m getting excited by what this allows. I&#8217;ll post more as I explore further. <\/p>\n<p>\n  <br \/>Now, all we need do is to deliver <a href=\"http:\/\/dn.codegear.com\/article\/36620#5DelphiTibur%C3%B3n\">Tiburon<\/a> to give me Generics in Win32, and I&#8217;ll be a happy boy.<\/p>\n<p><\/p>\n<p>Update : <a href=\"http:\/\/hallvards.blogspot.com\/\">Hallvard<\/a> has written up a good overview of generics in Highlander <a href=\"http:\/\/hallvards.blogspot.com\/2007\/08\/highlander2-beta-generics-in-delphi-for.html\">here<\/a><\/p>\n<p>&#160;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was traveling a bunch over the last two weeks, USA, Japan and Korea. In Osaka, I did a session on Generics for the Japan Developer Camp. Afterwards, I was having a further play with Highlander and Generics and stumbled across something rather nice. Maybe everyone else is aware of this already, but the new [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[98],"tags":[19,20,32],"class_list":["post-168","post","type-post","status-publish","format-standard","hentry","category-coding","tag-delphi","tag-generics","tag-nullable-types"],"_links":{"self":[{"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=168"}],"version-history":[{"count":3,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/168\/revisions"}],"predecessor-version":[{"id":1475,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/168\/revisions\/1475"}],"wp:attachment":[{"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=168"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}