zoukankan      html  css  js  c++  java
  • delphi override、overload、reintroduce的区别-0613.txt

    http://blog.csdn.net/honglixx/article/details/3624934
     1、override overload reintroduce的中文叫法是什么? 
      override:覆盖;overload:重载;Reintroduce:重定义 
    2、在子类中override或overload父类中的动态或虚拟方法后是否会改变父类中的相应方法? 
       不会 
    3、self是怎么回事,怎么使用? 
       Self因为这这个对象本身,例如,在TForm1的OnCreate事件中写Self指的是TForm1实例化后的对象,如果TForm1上有一个TButton叫做Button1,那么OnButton1Click中写的Self也是TForm1实例化后的对象, 
    4、reintroduce与override overload有何区别,怎么使用? 
        在子孙类中要声明一个与祖先类中参数不同的方法的时候用Reintroduce, 
        但需要重新定义一个祖先类总的虚拟的或者动态的方法的时候,要用到Override;如果祖先类中的方法不是虚拟的或者动态的(定义的时候有virtual;就是虚拟的,有dynamic;就是动态的);那么是没有办法override的 
        至于Overload,一般适用于定义一组不同参数的函数,这些函数也可以不是Of Objects(中文该怎么说?)。 
     reintroduce引入是为了屏蔽父类的一个虚方法,而在子类中生成一个新的方法;overload是为了处理同名的方法有不同的参数而设计的;   
      其实你不使用reintroduce也会覆盖屏蔽父类的方法的但是会产生一个警告,   
      使用了这个关键字,表明你要屏蔽这样不会产生警告的!
      
      
      
    如果类不从别的类继承(实际上也就是从TObject继承),
    constructor Create; virtual;   //virtual表示虚函数,表示可以被子类override;
    destructor Destory: virtual;
    如果从其它类继承,如:TForm
    constructor Create(AOwner: TComponent); override;
    destructor Destory: override;
    如果子类想再overload一个函数,则必须加上reintroduce和overload
    constructor Create(AOwner: TComponent); overload; override; //这里的overload必面在override之前.
    constructor Create(AOwner: TComponent; AParent: TWinControl); reintroduce; overload;
    
    例子
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;
    
    type
      Ta = class(TObject)
      public
        constructor Create; virtual;
        destructor Destory; virtual;
        procedure aaa; virtual;
      end;
      tb  = class(ta)
      public
        constructor Create; overload; override;
        constructor Create(a: String); reintroduce; overload;
        destructor Destory; override;
        procedure aaa; overload; override;
        procedure aaa(a: string); reintroduce; overload;
      end;
    
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
        c: tb;
      public
        { Public declarations }
      end;
    

      

  • 相关阅读:
    C# 从服务器下载文件
    不能使用联机NuGet 程序包
    NPOI之Excel——合并单元格、设置样式、输入公式
    jquery hover事件中 fadeIn和fadeOut 效果不能及时停止
    UVA 10519 !! Really Strange !!
    UVA 10359 Tiling
    UVA 10940 Throwing cards away II
    UVA 10079 Pizze Cutting
    UVA 763 Fibinary Numbers
    UVA 10229 Modular Fibonacci
  • 原文地址:https://www.cnblogs.com/rogge7/p/4422151.html
Copyright © 2011-2022 走看看