type
TTest = class
a: integer;
end;
TTest2 = class(TTest)
b: integer;
end;
var c:TTest;
begin
c:=TTest2.Create();
c.Free;
end;
type TTest = class a: integer; end; TTest2 = class(TTest) b: integer; end; var
Share
No, it will not.
A variable of a base class type can be used for instantiating objects from its child classes (they are type compatible), but take note that using such a variable, you will have access only to TTest members, not TTest2 members. That means; you can access “a”, but not “b”.
Also, if you face any exception during TTest2.Creation execution, Create won’t return a partially built object.
However, if you have some other codes between TTest2.Create and c.Free calls, raising an exception in those codes can cause memory leak; because C.Free might not execute. In such a case you should use a try-finally block.