Hi, Wagner
I'm try to implement Unit Test(DI, mocks, etc ), so i want to use interfaces. But interfaces
cannot have generic methods, and we use a lot in Aurelius.
TUserX = class
private
FName: String;
public
property Name: String read FName write FName;
end;
IDBBase = interface
function Get(Id: integer; Detailed: Boolean): TUserX;
function GetAll(Detailed: Boolean): TList<TUserX>;//Compiler don't support
end;
TDBCustomer = class(TInterfacedObject, IDBBase)
public
function Get(Id: integer; Detailed: Boolean): TUserX;
function GetAll(Detailed: Boolean): TList<TUserX>;
end;
i'm stuck, some suggestion?
Thank you very much.
That's a Delphi limitation unfortunately. Interfaces can't have generic methods, you can only have generic params in interface itself (e.g., IDBBase<T>).
Hi,
" Alternative is retrieve TObjectList or TList..."
how to do that?
function GetAll(Detailed: Boolean): TList;//?!
function GetAll(Detailed: Boolean): TObjectList;//?!
Thanks, Wagner
Yes, or TUserXList, it's your call, you will have to find the best solution that fits your needs to circumvent this limitation.
Sorry, Wagner
But, i'm using like this: TList<TObject> or TList<TUserX> or TObjectList<UserX>.
I don't understand what you meaning. Is there another way to use TList without generics?
Can you detail a bit more?
Thanks a lot
TList and TObjectList are normal Delphi types that exist way before generics. You can learn how to use them. Alternatively, you can declare a fixed type like this:
Hi, Wagner
After add "Contnrs" in uses, i understand what you mean.
Thank you very much