Hi,
related to my last question, I now have the following problem:
function TNodeFactory <T>.CreateNode (ID : Integer) : INodeInterface <T>;
var
NodeClass : TClass;
begin
NodeClass := FindRegisteredClass (ID);
Result := NodeClass.Create;
end;
This yields a compiler error:
E2010 Incompatible Types: 'INodeInterface<TNodeFactory<T>.T>' and 'TObject'
A cast does not work too.
What am I missing here?
EDIT: Current implementation
TNodeFactory <T> = class
private
type
TRegisteredNodeType = record
ID : Integer;
NodeClass : TClass;
end;
private
FNodeTypeList : TList <TRegisteredNodeType>
public
procedure RegisterNodeType (ID : Integer; NodeClass : TClass);
function CreateNode (ID : Integer) : INodeInterface <T>;
end;
procedure TNodeFactory <T>.RegisterNodeType (ID : Integer; NodeClass : TClass);
var
RegisteredType : TRegisteredNodeType;
begin
RegisteredType.ID := ID;
RegisteredType.NodeClass := NodeClass;
FNodeTypeList.Add (RegisteredType);
end;
function TNodeFactory <T>.CreateNode (ID : Integer);
var
RegisteredType : TRegisteredNodeType;
begin
for RegisteredType in FNodeTypeList do
if (RegisteredType.ID = ID) then
Exit (RegisteredType.NodeClass.Create);
raise EInvalidNodeType.Create ('No node type with ID ' + IntToStr (ID) + ' registered');
end;
(simplified and removed error checks)