1. No, it's not virtual
2. Overriding a default constructor create is also not possible for classes: the default constructor is not virtual. It also does not make sense.
https://www.freepascal.org/docs-html/rtl/system/tobject.create.htmlNow the fun part: in FPC (trunk) we have management operators that can do what you want: setting things to other values than just zero's and nil's.
http://wiki.freepascal.org/management_operatorsI have written several examples in the wiki. Management operators are called
automatically.
I 'll show you a slightly modified example of my wiki example that uses the Initialize management operator:
{$if FPC_FULLVERSION < 30101}{$ERROR this demo needs version 3.1.1 or higher}{$endif}
{$mode delphi}{$macro on}
program TestInitialize;
type
PRec = ^TRec;
TRec = record
I : Integer;
class operator initialize(var aRec:TRec);
end;
class operator TRec.initialize(var aRec:TRec);
begin
//aRec :=Default(TRec); // initialize to default
FillChar(aRec,SizeOf(aRec),$FF); // initialize to all $FF instead of default.
end;
procedure printTRec(r : PRec);
begin
WriteLn('Initialized TRec field i: ', r^.I = -1); // should now be $ffffffff (-1) and so print TRUE.
end;
var
a,b:PRec;
begin
New(a);New(b); // standard "new" does not initialize, but now it does!
PrintTRec(a);
PrintTRec(b);
Dispose(a);Dispose(b);
end.
Note
you can't do that in Delphi. This feature is specific to FreePascal.
Note for classes you can do something similar by overriding
newinstance.
Note that you are also making the
wrong assumption that records are always initialized to zero's: That is not the case.... See New()/Dispose() and Default()