Does the `overload` keyword make any difference?
delphi, overloading
Solution
The big difference is that when the arguments to a method are incorrect, the error message is significantly better for a non-overloaded method.
program Test;
procedure F(X: Integer);
begin
end;
procedure G(X: Integer); overload;
begin
end;
var
P: Pointer = nil;
begin
F(P); // E2010 Incompatible types: 'Integer' and 'Pointer'
G(P); // E2250 There is no overloaded version of 'G' that can be called with these arguments
end.
More subtly, an overloaded method may be overloaded with functions you have no knowledge of. Consider the standard `IfThen` function. `StrUtils.IfThen` exists exactly once:
function IfThen(AValue: Boolean; const ATrue: string;
AFalse: string = ''): string; overload; inline;
yet it is marked as `overload`. That's because it's overloaded with `Math.IfThen`, and if a single unit uses both `Math` and `StrUtils`, an unqualified `IfThen` will resolve to the proper function depending on the arguments, and regardless of the order of the units in the `uses` list.
Problem
Sometimes I have the "overload" keyword after a method that's not overloaded. Besides readability and maintainability of the code, does this have any other impact that I should be aware of?