Similar to function overloading, method overloading simply means that the same method is defined more than once in the same class, but each time with a different formal parameter list.
The parameter lists must differ at least in one of its element types. When the compiler encounters a method call, it will look at the method’s parameters to decide which one of the defined methods it should call. This can be useful when the same method must be defined for different types.
For example, in the TStrings class of the Classes unit, the AddStrings method has many overloads
procedure AddStrings(TheStrings: TStrings); overload; virtual; procedure AddStrings(TheStrings: TStrings; ClearFirst : Boolean); overload; procedure AddStrings(const TheStrings: array of string); overload; virtual; procedure AddStrings(const TheStrings: array of string; ClearFirst : Boolean); overload;
When the compiler encounters a call to the AddStrings method, it will first search which method it should use. It therefore checks the parameters in a method call, and looks if there is a method definition which matches the specified parameter list. If the compiler finds such a method, a call is inserted to that function. If no such method is found, a compiler error is generated.
If the overload keyword is not present, then all overloaded versions of the method must reside in the same class, i. e. the compiler will not look for overloaded methods in parent classes if the overload keyword was not specified.