TTest= class
public abc:Integer;
type
TTest2 = class
procedure test;
end;
end;
procedure TTest.TTest2.test();
begin
abc:=5; //'Inaccessible here'
end;
I get 'instance member abc not accessible here'.
The situation is serious. I have to use a thread, but since TThread is abstract, own class should inherit it. In my case the class that needs the thread already inherits another class that cannot inherit TThread... so this is not possible. My scenario is the nested class to inherit TThread and below I declare it. But the Execute(); method must use members of its parent class.
How do I do it? Why this error?
The inner class is exactly that: a separate class. Only its name scope is nested inside of the parent class. You can construct an instance of the inner class without an instance of the parent class.
If you make the abc member a class variable, then you can access it from the inner class because class vars have global storage independent of the object instances.
Otherwise, you will need to pass an instance of the parent class into the nested class in order for the nested class to write to the parent instance's fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With