The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,497 other followers

Workaround for Delphi 2010 compiler error “E2076 This form of method call only allowed for class methods” when it infers a generic parameter type.

Posted by jpluimers on 2015/09/10

Generic support in Delphi took a very long time to get stabilised. Which means that compilers older than Delphi XE2 are hardly usable for code using generics. XE did get better, but Delphi 2010 and especially Delphi 2009 were hopeless.

A while ago, I bumped into another subtle error “E2076 This form of method call only allowed for class methods” when back-porting to Delphi 2010 the code like below calling the Spring4D unit Spring.SystemUtils which has a TEnum class that includes this TEnum.GetName<T> method:

    class function GetName<T>(const value: T): string; overload; static;

In Delphi XE and up, you do not have to specify the generic parameter T: the compiler automatically infers it.

In Delphi 2010, you have to, otherwise you will get the (totally unrelated!) error “E2076 This form of method call only allowed for class methods“.

Example code:

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: