zoukankan      html  css  js  c++  java
  • 方法重载

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;
    
    type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    //有方法重载的类
      TMyClass = class
      public
        procedure MyProc(i: Integer); overload;
        procedure MyProc(s: string); overload;
        function MyProc(s1,s2: string): string; overload;
      end;
    //关于方法重载:
    //过程和函数之间可以重载
    //类内重载必须有 overload 关键字
    //子类重载必须有 overload 关键字,夫类可以没有
    //如果夫类是虚函数(virtual dynamic),子类重载时需要加 reintroduce 修饰词
    //published 区内不能重载
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    { TMyClass }
    
    procedure TMyClass.MyProc(i: Integer);
    begin
      ShowMessage(IntToStr(i));
    end;
    
    procedure TMyClass.MyProc(s: string);
    begin
      ShowMessage(s);
    end;
    
    function TMyClass.MyProc(s1, s2: string): string;
    begin
      Result := s1 + ' and ' + s2;
    end;
    
    //测试
    procedure TForm1.FormCreate(Sender: TObject);
    var
      class1: TMyClass;
    begin
      class1 := TMyClass.Create;
    
      class1.MyProc(2);  //2
      class1.MyProc('2');  //2
      ShowMessage(class1.MyProc('2','3'));  //2 and 3
    
      class1.Free;
    end;
    
    end.
    
  • 相关阅读:
    解决asp.net mvc的跨域请求问题
    centos安装nodejs
    webapi中配置返回的时间数据格式
    centos安装django
    在Linux CentOS 6.6上安装Python 2.7.9
    nginx日志切割脚本
    apache单ip配置多端口多站点
    centos开启rewrite功能
    Fast Matrix Operations
    1400
  • 原文地址:https://www.cnblogs.com/del/p/983733.html
Copyright © 2011-2022 走看看