给你一段经典代码function Max(A,B: Integer): Integer; overload;
function Max(A,B: Int64): Int64; overload;
function Max(A,B: Single): Single; overload;
function Max(A,B: Double): Double; overload;
function Max(A,B: Extended): Extended; overload;
function Max(A,B: Int64): Int64; overload;
function Max(A,B: Single): Single; overload;
function Max(A,B: Double): Double; overload;
function Max(A,B: Extended): Extended; overload;
如下例:声明:
T1 = class
procedure f1;
procedure f2;virtual;
end;T2 = class (T1)
procedure f1;
procedure f2:override;
end;...执行代码:
...
var
a: T1;
b: T2;
begin
b := T2.Create;
a := b; //将b:T2类实例的引用转为T1类实例的引用
a.f1; // 将调用T1.f1 【静态方法】
a.f2; // 将调用T2.f2 【虚方法】
...
end;2.使用重载可以增加代码的复用性与可读性.