0

I want to implement a generic class TB, which inherits from another generic class, TA as shown below

base = class(Tobject)
public
 procedure test1( x : integer ); virtual;
end;


generic TA<T>= class (base )
public 
 procedure test1( x : T ); overload;
end;

generic TB< T, Y >= class (TA<T>)
public 
 procedure test1( addParameter1 : T ; addParameter2 : Y ); overload;
end;

But it does not work! Any idea how I can do that.

2
  • 3
    T is not defined in base, and generic is not a keyword. Commented Oct 24, 2014 at 4:59
  • 4
    "It does not work" is not very helpful. What are you hoping to achieve? It's easy enough to fix the compiler errors but the code won't do anything useful. I sense that you are struggling greatly with a design problem. I believe that you'll gain the most enlightenment here if you ask about the problem rather than your solution. Commented Oct 24, 2014 at 5:51

1 Answer 1

1

You are on the right track, but you can't define your Base class with a generic parameter without making it generic (the parameter to procedure test1 is of type "T" which is unknown in this context - Edit: Code has since been altered - see edit revisions). A class must be 100% self-contained and must be able to be syntactically parsed and constructed without reliance of any descendant classes.

So either you must make Base a generic class, or you must remove the reliance of type T from it.

Other than that your code should compile, if you remove the "generic" word, as there is no such keyword in Delphi, and prefix the entire code snippet with "Type".

Sign up to request clarification or add additional context in comments.

1 Comment

Making the code compile is simple enough. But then what? What use is that virtual function in the non generic base class? Can you address that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.