Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Created December 27, 2014 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpluimers/25a55959ca3ae90371d9 to your computer and use it in GitHub Desktop.
Save jpluimers/25a55959ca3ae90371d9 to your computer and use it in GitHub Desktop.
Workaround for Delphi 2010 compiler error "E2076 This form of method call only allowed for class methods" when it infers a generic parameter type.
uses
Spring.SystemUtils;
procedure Test;
var
RuntimeError: TRuntimeError;
Name: string;
begin
RuntimeError := reNone;
// in the Spring.SystemUtils unit:
// class function TEnum.GetName<T>(const value: T): string;
// Workaround in Delphi 2010 (also works in Delphi XE+, but these do not require the Generic type to be specified).
Name := TEnum.GetName<TRuntimeError>(RuntimeError);
// Delphi 2010 does infer the type of the generic parameter, but then barfs with error E2076.
// Delphi XE+ infers the parameter type and do not generate an error: no need to explicitly specify the generic type:
Name := TEnum.GetName(RuntimeError); // Delphi 2010: [DCC Error] : E2076 This form of method call only allowed for class methods
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment