Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 305579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:23:13+00:00 2026-05-12T07:23:13+00:00

related to my last question , I now have the following problem: function TNodeFactory

  • 0

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)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:23:13+00:00Added an answer on May 12, 2026 at 7:23 am

    The problem is NodeClass being a TClass. If you create NodeClass it will be a mere TObject, not a INodeInterface.

    You could try

    Result := TInterfacedObject(RegisteredType.NodeClass).Create as INodeInterface
    

    or change RegisterNodeType to

    type
      TInterfacedObjectClass = class of TInterfacedObject;   
    ...   
    procedure RegisteredNodeType...(ID: Integer; NodeClass : TInterfacedObjectClass);
    

    and return

    Result := RegisteredType.NodeClass.Create as INodeInterface. 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on a web services related project for about the last
Much related to this question , we have a scenario on my team where
Hi I have a Subclipse related question. In SVN when you merge the trunk
I have looked a bit into cryptography and related matters during the last couple
I have an SQL question, related to this and this question (but different). Basically
this is related to my last question ( NOTE: I already got some good
Related to https://stackoverflow.com/questions/139944/where-can-one-find-free-software-icons-images I have a need for free weather-related icons. Specifically, I need
Related to this question , I decided to check the UDFs in my data
Related to this question: URL characters replacement in JSP with UrlRewrite I want to
Related to this question , what is the best practice for naming a mutex?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.