方法重载

类 / 方法

type
  TShow = class
  public
    //overload marks every version
    class procedure ShowParams(
      const V: string); overload;
    class procedure ShowParams(
      V: Integer); overload;
    class procedure ShowParams(
      V: Boolean); overload;
    class procedure ShowParams(
      const V1: string;
      V2: Integer); overload;
  end;

class procedure TShow.ShowParams(
  const V: string);
begin
  WriteLn(V);
end;

class procedure TShow.ShowParams(V: Integer);
begin
  WriteLn(V);
end;

class procedure TShow.ShowParams(V: Boolean);
begin
  WriteLn(V);
end;

class procedure TShow.ShowParams(
  const V1: string; V2: Integer);
begin
  WriteLn('(', V1, ', ', V2, ')');
end;

begin
  //the compiler picks by the arguments
  TShow.ShowParams('A');
  TShow.ShowParams(66);
  TShow.ShowParams(True);
  TShow.ShowParams('B', 67);
  //A
  //66
  //TRUE
  //(B, 67)
end.