Say I have this interface:
Say I have this interface:
IMyInterface = interface
//guid
procedure DoSomething(const aCon: T);
end;
then this class:
TMyClass = class (TInterfacedObject, IMyInterface)
private
fEntity: T;
public
constructor Create;
procedure DoSomething (const aCon: T);
end;
Now, I want to create a function which generates TMyClass--something like this:
function createMyClass (?????): IMyInterface
begin
result:=TMyClass.Create
end;
How do I pass the generic entity "T" to a function? I though to use a parameter of TObject but not sure if it is correct.
Thanks
IMyInterface
//guid
procedure DoSomething(const aCon: T);
end;
then this class:
TMyClass
private
fEntity: T;
public
constructor Create;
procedure DoSomething (const aCon: T);
end;
Now, I want to create a function which generates TMyClass--something like this:
function createMyClass (?????): IMyInterface
begin
result:=TMyClass.Create
end;
How do I pass the generic entity "T" to a function? I though to use a parameter of TObject but not sure if it is correct.
Thanks
Currently Delphi doesn't support plain functions or procedures with generics. Methods in classes and records are OK.
ReplyDeleteAlso, why define DoSomething() in the Public section - it is a Interface method, so move it to the Private section of TMyClass and promote the usage via a interface reference only (the whole point of interfaces).
ReplyDeleteGraeme Geldenhuys Yes you're right--that was just the example I wrote here
ReplyDelete