2016-07-28 16:37 GMT+02:00 Michael Van Canneyt <mich...@freepascal.org>: > > Are there additional benefits I have missed ? > > Using nilable (I think nilable is better than nullable) records is terrible without default field:
=== code begin === var n: TNilable<TRec>; x: TRec; begin { ... let say that n is assigned somewhere, assume that n.HasValue = true } // to change any field in nilable n you need to... x := n.Value; x.foo1 := 10; x.foo2 := 'abc'; n := x; end. === code end === instead of: === code begin === var n: TNilable<TRec>; begin { ... let say that n is assigned somewhere, assume that n.HasValue = true } x.foo1 := 10; x.foo2 := 'abc'; end. === code end === > I can live with the 'ascetic' version :-) > > Since the following: > > Procedure SomeTest(Var X : Integer); > > begin > X:=1; end; > > Var > A : TNullable<Integer>; > > begin > SomeTest(A^); > end. > > Will lead to a crash on a null value, I don't think this is a very good > idea to add. > We should protect users from crashes, not expose them to it :-) > that will change nothing, just look below. Just harder to usage pure non-pascalish clone of C# struct (finally C# has pointers as nonstandard/unsafe type so feature with direct dereference is disabled by design). === code begin === procedure SomeTest(x : Integer); begin end; Var A : TNullable<Integer>; begin SomeTest(A.Value); // AV error here! end. === code end ==== A^ is shortcut for A.Value but has advantage = direct dereference to Instance. -- Best regards, Maciej Izak
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel