delphi.gif (306 バイト) メソッドのオーバーロード


Delphi4から同じ名前を持つメソッドが宣言できるようになりました。つぎの例は、コンストラクタのものですが、一般のメソッドでももちろん可能です。

delphi1.gif (322 バイト) 

type
TMyClass = class(TObject)
private
    FValue: Integer;
public
    constructor Create; overload;
    constructor Create(n: Integer); overload;
    function GetValue: Integer;
end;

 

constructor TMyClass.Create;
begin
    inherited Create;
    FValue := 0;
end;

constructor TMyClass.Create(n: Integer);
begin
    inherited Create;
    FValue := n;
end;