What's the best way to get around the shortcoming of generic type inferencing of reference arguments, so that I don't have to specify the type in every call?
Update: I don't mind other (including non-generic) solutions as long as it works with multiple (any?) types.
This seems to still not have been resolved, although known for quite some time.
Please vote for a resolution to this on Embarcaderos Quality Central: Issue #78103.
From a comment by Barry Kelly to Generic Methods and Type Inferencing:
PS: Your example, in Tiburon, almost works. Method type inference works well for arguments passed by value. It doesn’t work for arguments passed by reference, unfortunately (the compiler is being too strict).
Now, almost three years later, I'm trying the same thing in Delphi XE, and it complains that:
[DCC Error] INIv1_Parser.pas(81): E2033 Types of actual and formal var parameters must be identical
When calling:
function FindDataItemValue<T>(ItemType: TDataItemType; out Value: T): Boolean;
With:
var MaxG: Real;
...
if Data.FindDataItemValue(PAR_MaxG, MaxG) and (MaxG = 2.5) then ...
Commonly suggested work-around: However, if I add the generalization on the call, it works fine; although annoying that it is even needed.
Update:
Thus far, The best I've come up with is to use either Variants or the TValue record from the Rtti module. Using variants I implement interfaces when I need to use objects, and store a reference to that (interface) in the variant.