I have written this simple code:
type
TTestA = class
strict protected
a: integer;
public
f: integer;
constructor Create(x: Integer);
end;
type
TTestB = class(TTestA)
strict private
c: integer;
end;
I use strict because these classes are in the same unit as the TForm1 class. Since a is protected by definition, it should be accessible only in subclasses, but then why this code doesn't work?
procedure TForm1.Button1Click(Sender: TObject);
var
K: TTestB;
begin
k := TTestB.Create(3);
value = k.a; //I cannot access a
end;
Also, the protected can be useful to create an abstract class. In C++, if I declare a constructor as protected, I cannot create an instance of the object and only subclasses can. Can Delphi do this?
I am having the same problem with the variable and the constructor.