[fpc-pascal] with in classes/records

Michael Van Canneyt michael at freepascal.org
Thu Sep 6 16:25:13 CEST 2018

On Wed, 5 Sep 2018, Ryan Joseph wrote:

>> On Sep 4, 2018, at 7:15 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>> The idea of the default property is that *all* operators (and methods) (except management operators) are hoisted from the type of the default property. The assignment of one record with default property to another of the same type is handled by the Copy management operator. 
> I just realized that default shouldn’t be allowed on non-object fields
> right?  I think that’s what was decided and makes most sense to me too. 
> Disregard my last email.  Sorry if I make a bunch of noise while I’m
> working on this but I’m probably going to have lots of questions coming
> up.

No, the whole point of default is that they should be for any kind of field.
For example if you want a nullable boolean, you'll do something like

     TNullable<T>= Record
       F : T;
       isAssigned : Boolean;
       Function GetValue : T;
       Procedure SetValue(aValue : T);
       Property Value : T Read GetValue Write SetValue; default;
       Property IsNull : Boolean Read GetISNull Write SetIsNull;

   B : TNullable<Boolean>;

   Writeln(B.IsNull); // Should be true
   B:=True;           // Works due to default.
   Writeln(B.IsNull); // Should be false.


> Regards,
> 	Ryan Joseph
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

More information about the fpc-pascal mailing list