[fpc-pascal] Option type

Sven Barth pascaldragon at googlemail.com
Tue Jun 1 22:40:07 CEST 2021

Am 01.06.2021 um 20:20 schrieb denisgolovan via fpc-pascal:
> Hi all
> I am trying to implement Option<T> type in FPC.
> type
>    generic TOption<T> = record
>      case IsSome:boolean of
>      true: ( some: T );
>      false: ();
>    end;
> However fpc just emits errors:
> Error: Type parameters may require initialization/finalization - cannot be used in variant records

You simply can't use managed types in a variant clause and as T could be 
a managed type the compiler does not allow it.

> Could anybody suggest some sane workaround for the problem?

Use Nullable.TNullable<T>.


More information about the fpc-pascal mailing list