delphi 重载 重写
Functions and procedures are an important part of the Delphi language. Starting with Delphi 4, Delphi allows us to work with functions and procedures that support default parameters (making the parameters optional), and permits two or more routines to have an identical name but operate as completely different routines.
函数和过程是Delphi语言的重要组成部分。 从Delphi 4开始,Delphi允许我们使用支持默认参数的函数和过程(使参数成为可选参数),并允许两个或多个例程具有相同的名称,但作为完全不同的例程进行操作。
Let's see how Overloading and default parameters can help you code better.
让我们看看重载和默认参数如何帮助您更好地编码。
超载 ( Overloading )
Simply put, overloading is declaring more than one routine with the same name. Overloading allows us to have multiple routines that share the same name, but with a different number of parameters and types.
简而言之,重载声明了多个同名例程。 重载使我们可以拥有多个共享相同名称,但参数和类型数量不同的例程。
As an example, let's consider the following two functions:
作为示例,让我们考虑以下两个功能:
{Overloaded routines must be declared
with the overload directive}
function SumAsStr(a, b :integer): string; overload