Let's say I have a class with two common methods:
TMyClass = class procedure DoWith<T: class> (obj: T); procedure DoFor<T: class> ( proc: TProc<T> ); end;
Now, when I want to call either of these two methods with a specific type parameter, Delphi can infer the type for the DoWith method, so I can call it with
MyClass.DoWith <TButton> ( MyButton )
or
MyClass.DoWith ( MyButton )
The Delphi compiler will be happy to compile both. But if I omit the type parameter in the DoFor method, the Delphi compiler complains about the missing type parameter:
MyClass.DoFor<TButton>(procedure (Button: TButton) begin .... end); // compiles MyClass.DoFor(procedure (Button: TButton) begin .... end); // doesn't compile
Now my question is: is this just a flaw of the compiler, or is there some logical reason (which I haven't figured out yet) that prevents the compiler from correctly DoFor type of the DoFor method?
source share