Smart pascal source code
type
TClassA = class
Field: String;
constructor Create; virtual;
end;
type
TClassB = class(TClassA)
constructor Create; override;
end;
constructor TClassA.Create;
begin
Field := 'A';
end;
constructor TClassB.Create;
begin
Field := 'B';
end;
var o, o2: TClassA;
o := TClassA.Create;
WriteLn(o.Field);
o2 := o.Create;
WriteLn(o2.Field);
o := TClassB.Create;
WriteLn(o.Field);
o2 := o.Create;
WriteLn(o2.Field);
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
Errors >>>>
Warning: Constructor invoked on instance outside of constructor [line: 26, column: 7]
Warning: Constructor invoked on instance outside of constructor [line: 31, column: 7]
Result >>>>
A
A
B
B
-----------------------------
{<<<<<<<<< THE END >>>>>>>>>}
var TClassA = {
$ClassName:"TClassA",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
$.Field = "";
}
,Create$3:function(Self) {
$Check(Self,"").Field = "A";
return Self
}
,Destroy:TObject.Destroy
,Create$3$:function($){return $.ClassType.Create$3($)}
};
var TClassB = {
$ClassName:"TClassB",$Parent:TClassA
,$Init:function ($) {
TClassA.$Init($);
}
,Create$3:function(Self) {
$Check(Self,"").Field = "B";
return Self
}
,Destroy:TObject.Destroy
,Create$3$:function($){return $.ClassType.Create$3($)}
};
var o = null;
var o2 = null;
/* <<< main JS >>> */
o = TClassA.Create$3$($New(TClassA));
WriteLn($Check(o,"").Field);
o2 = TClassA.Create$3$($Check(o,""));
WriteLn($Check(o2,"").Field);
o = TClassA.Create$3$($New(TClassB));
WriteLn($Check(o,"").Field);
o2 = TClassA.Create$3$($Check(o,""));
WriteLn($Check(o2,"").Field);