Inherited constructor



Inherited constructor
Smart pascal source code
function CreateElement: TObject; begin Result := new TObject; end; Type TComponent = Class(TObject) Private FObjRef: TObject; Public Property Handle: TObject read FObjRef; Constructor Create(AOwner: TComponent); virtual; End; Constructor TComponent.Create(AOwner: TComponent); Begin FObjRef := CreateElement; end; Type TCustomControl = Class(TComponent) public Constructor Create(AOwner: TComponent); override; End; Constructor TCustomControl.Create(AOwner: TComponent); Begin if assigned(Handle) then writeln('We have a handle') else writeln('We dont have a handle'); end; Type TCustomControl2 = Class(TComponent) public Constructor Create(AOwner: TComponent); override; End; Constructor TCustomControl2.Create(AOwner: TComponent); Begin inherited Create(AOwner); if assigned(Handle) then writeln('We have a handle') else writeln('We dont have a handle'); end; var mObj: TComponent; mObj := TCustomControl.Create(NIL); mObj := TCustomControl2.Create(NIL); {<<< RESULT - CONSOLE LOG >>> ----------------------------- Errors >>>> Hint: "createElement" does not match case of declaration ("CreateElement") [line: 17, column: 12] Hint: "assigned" does not match case of declaration ("Assigned") [line: 28, column: 6] Hint: "println" does not match case of declaration ("PrintLn") [line: 29, column: 3] Hint: "println" does not match case of declaration ("PrintLn") [line: 30, column: 3] Hint: "assigned" does not match case of declaration ("Assigned") [line: 42, column: 6] Hint: "println" does not match case of declaration ("PrintLn") [line: 43, column: 3] Hint: "println" does not match case of declaration ("PrintLn") [line: 44, column: 3] Result >>>> We dont have a handle We have a handle ----------------------------- {<<<<<<<<< THE END >>>>>>>>>}