Difference between revisions of "Nullable types"
From Free Pascal wiki
Jump to navigationJump to search (Added variant on see also) |
(delete pas code, give URL instead) |
||
Line 5: | Line 5: | ||
Same behavior can be implemented using [[Generics|generic types]] and advanced records with [[Operator overloading|operator overloading]]. | Same behavior can be implemented using [[Generics|generic types]] and advanced records with [[Operator overloading|operator overloading]]. | ||
− | + | The Nullable unit is part of FPC since 3.2.2. Its code in the GitLab: [https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/rtl-objpas/src/inc/nullable.pp nullable.pp]. | |
− | unit | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Then you can define nullable types like: | Then you can define nullable types like: |
Revision as of 12:19, 4 March 2022
│
English (en) │
suomi (fi) │
Nullable types are types which can have no value (can be unassigned).
One such type in Pascal is Pointer type which can have nil
value which means that it isn't assigned to any specific address.
Same behavior can be implemented using generic types and advanced records with operator overloading.
The Nullable unit is part of FPC since 3.2.2. Its code in the GitLab: nullable.pp.
Then you can define nullable types like:
NullableChar = TNullable<Char>;
NullableInteger = TNullable<Integer>;
NullableString = TNullable<string>;
See also
The standard nullable type in Object Pascal is Variant.