-
-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new DEMO NullableTypesShowcase
- Loading branch information
1 parent
42e0bc1
commit 0f1e8f7
Showing
2 changed files
with
1,273 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
program NullableTypesShowcase; | ||
|
||
{$APPTYPE CONSOLE} | ||
|
||
{$R *.res} | ||
|
||
uses | ||
System.SysUtils, | ||
MVCFramework.Nullables; | ||
|
||
|
||
procedure Main; | ||
begin | ||
var lNullableInt: NullableInt32; | ||
Assert(lNullableInt.IsNull); | ||
Assert(not lNullableInt.HasValue); | ||
Assert(lNullableInt.ValueOrDefault = 0); | ||
lNullableInt := 3; // compatible with base type | ||
Assert(not lNullableInt.IsNull); | ||
Assert(lNullableInt.HasValue); | ||
Assert(lNullableInt.ValueOrDefault = 3); | ||
Assert(lNullableInt.Value = 3); | ||
|
||
var lVal: Integer; | ||
if lNullableInt.TryHasValue(lVal) then | ||
begin | ||
// work with value... | ||
{ | ||
TryHasValue is a shortcut for the following code: | ||
if lNullableInt.HasValue then | ||
begin | ||
var lVal := lNullableInt.Value; | ||
// work with value... | ||
end; | ||
} | ||
end; | ||
|
||
lVal := lNullableInt; // compatible with base type - equivalent to lNullableInt.Value | ||
{ | ||
lNullableInt.Value raises exception if "lNullableInt.IsNull = True" | ||
} | ||
end; | ||
|
||
begin | ||
try | ||
Main; | ||
except | ||
on E: Exception do | ||
begin | ||
Writeln(E.ClassName, ': ', E.Message); | ||
end; | ||
end; | ||
Write('Press return to continue'); | ||
Readln; | ||
end. |
Oops, something went wrong.