Created
December 27, 2014 21:13
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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