Commits

Nick Hodges committed 0a0a0c8

Fleshed out the nullable demo

  • Participants
  • Parent commits 10f7d13

Comments (0)

Files changed (1)

File SpringDemos/Demo.General/Demo.Spring.Nullable.dpr

    , Variants
    ;
 
-
-
 procedure ShowThreeStates(aThreeStateBoolean: TNullableBoolean);
 begin
-  case aThreeStateBoolean.Value of
-    True:  Writeln('True');
-    False: Writeln('False');
-//    nil  : WriteLn('nil');
-  else
+  if aThreeStateBoolean.HasValue then
+  begin
+    if aThreeStateBoolean.Value then
     begin
-      WriteLn('Value is unknown.');
+      Writeln('True')
+    end else
+    begin
+      Writeln('False')
     end;
+  end else
+  begin
+    Writeln('Value has not been set.')
   end;
 end;
 
 
 begin
   try
-    NullableBoolean := TNullableBoolean.Create(Null);
+    try
+      WriteLn(NullableBoolean.Value);
+    except on E: EInvalidOperation do
+      WriteLn('Value has not been set, EInvalidOperation properly thrown');
+    end;
     ShowThreeStates(NullableBoolean);
     NullableBoolean := True;
     ShowThreeStates(NullableBoolean);