How to inherit from a class with a protected data type?

时间:2016-06-18 20:20:30

标签: delphi inheritance protected

I have a base generics class with an inner protected class. How do I inherit from the base class and access the protected inner class?

As an example this code will not compile:

unit uFoo;

interface

type

  TFoo<T> = class
  protected
    type
      TFooProtected = class

      end;
  end;

  TFoo2<T> = class(TFoo<T>)
  protected
    item: TFooProtected;
  end;

1 个答案:

答案 0 :(得分:6)

Like this:

type
  TFoo<T> = class
  protected
    type
      TFooProtected = class
      end;
  end;

  TFoo2<T> = class(TFoo<T>)
  protected
    item: TFoo<T>.TFooProtected;
  end;

Note that this has nothing to do with generics. It is valid for any class where the type is declared internally.