1

I am trying to do somenthing like the following:

type
  IExemplo<Generic> = interface
    function GetGenerico: Generic;    
  end;

  TClassA<Generic> = class(TComponent, IExemplo<Generic>)
    function GetGenerico: Generic; virtual;
    function GetInterface: IExemplo<Generic>; virtual;
  end;

  TClassB = class(TClassA<string>)
    function GetGenerico: string; override;
    function GetInterface: IExemplo<string>; override;
  end;

In other words, I create an interface that has some Generics, a base class to implement the interface, and finally a derived class to implement the base class.

But, in the line

function GetInterface: IExemplo<string>; override;

I am getting a syntax error.

My goal is for TClassB to no longer have the Generic attribute, at this point its type has already been properly set.

1 Answer 1

4

This code is valid and compiles in later versions of Delphi. Indeed, it compiles for me with Delphi 2010, and so I wonder if you perhaps have not installed all the updates that are available for Delphi 2010.

Delphi generics were riddled with defects in the early releases. By some distance, the most pragmatic approach is for you to upgrade to a modern version of Delphi in order to escape the tyranny of these defects. Yes, you may get around the problem by installing updates to Delphi 2010, but I am sure that you will encounter other problems with generics before long.

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

Comments

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.