[Lazarus] two questions about generics

Sven Barth pascaldragon at googlemail.com
Fri Feb 22 12:57:25 CET 2013


On 22.02.2013 10:31, Xiangrong Fang wrote:
> Thanks Sven.  In the case I use Default() does it mean it always has
> fixed defaults with specific types, e.g. 0 for integer '' for string. Or
> I can set my own default value?

It is a fixed default value. Simply spoken it's always zero. Even in 
cases like the following:

=== example begin ===

type
   TTest = record
     case Boolean of
       True: (a: 5..10);
       False: (b: -10..-5);
   end;

var
   t: TTest;
begin
   t := Default(TTest);
   Writeln(t.a); // 0
   Writeln(t.b); // 0
end.

=== example end ===

Regards,
Sven




More information about the Lazarus mailing list