[fpc-devel] Generics problem

Andrew Brunner andrew.t.brunner at gmail.com
Wed May 26 04:48:44 CEST 2010


I've just encountered a generics problem and wanted to know if it was
intentional...

uGenerics.pas

generic GObjectList<_T>=class(TList)
    private
      FIndex : integer;
    private
      function  Get(Index:integer): _T;
      procedure Put(Index:integer; Item:_T);
    public
      constructor Create; virtual;
      destructor Destroy; override;
    public
      function  Add(Item: _T):integer;
      function  Delete(Item: _T):integer;
      function  IndexOf(Item:_T):integer;
      function  Next:_T;
    public
      property  Items[Index: integer]: _T read Get write Put; default;
    end;

---------------------------

uCoreObjects.pas

TCoreObjects=class;
.
.
.
  GCoreObjects=specialize GObjectList<TCoreObject>;
  TCoreObjects=class (GCoreObjects)
  private
    FLastError             : cardinal;
  protected
    FRequest               : THTTPRequest;
    FResponse              : THTTPResponse;
    FServer                : TRSRServer;
    FManager               : TRSRManager;
    FAccounts              : TUserAccounts;
    FFat                   : TDSFat;
    FDomainP               : PDomain; //  Why can't I access this
field in a descendant class
    FKeywordsP             : PKeywords;
  public
    function IndexOf(var NameSpace:string):integer; overload;
  public
    function Execute(var Params:TCoreParams; Var RSR:TRSR; var
Keywords:TKeywords):Cardinal; overload;
    function Execute(iIndex:integer; var Params:TCoreParams; Var
RSR:TRSR; Var Keywords:TKeywords):Cardinal; overload;
  public
    property LastError:Cardinal read FLastError;
  public
    constructor Create(aServer:TRSRServer; aManager:TRSRManager;
aDomainP:PDomain; aKeywordsP:PKeywords; aFat:TDSFat;
aAccounts:TUserAccounts; aRequest:THTTPRequest;
aResponse:THTTPResponse); reIntroduce;
    destructor Destroy; override;
  end;

---------------------------

unit coAdmin.pas

TAdminCore=Class(TCoreObject)
 .
.
.
TAdminCore.MethodName(foo);
begin
  FList.FDomainP    << Does not compile.  For some reason I get
"Error: identifier indents no member "FDomainP"....
end;

Descendant classes for TCoreObject that reference a Fleshed out
Generic does not allow me to access protected fields... Is this
intentional? I would like to make the argument that since the classes
are in the same hierarchical level - FPC should resolve the
reference...

I also tried making the FList member public but to no avail... Any thoughts?



More information about the fpc-devel mailing list