inherited在命令里到底是什么意思,起什么作用的?
看别人的程序,命令按钮里面就一句话,‘inherited’,
看别人的程序,命令按钮里面就一句话,‘inherited’,
解决方案 »
- 关于在edit里设定点问题,就像IP地址输入那样的编楫框
- 请解释解释这个语法的意思????????
- 为什么我的程序在运行时占用很大的内存!!!!!
- delphi在声明部分出错,很奇怪,为什么?
- 怎么通过出生日期计算年龄
- 请教:三层结构怎么玩?up有分。
- delphi6是否需要ado补丁,有这方面经验的高手进来谈谈
- 怎样判断单击了一个按钮 if 单击 then ....
- 如何汉化用installshied制作的安装程序
- 请问,怎么倒数据库??????????
- 转水圆帖:大家来回复我的帖子,然后察看页面源代码;找历史最悠久的注册UsrID人,欢迎大家热烈响应。
- 如何实现即时更新ListView显示内容!
begin
inherited;
if rbLogout.Checked then
fmMain.Caption := '进销存管理系统';
end;
unit MyClass;interfaceuses Dialogs;type
Ta = class
public
procedure Test();
end; Tb = class(Ta)
public
procedure Test();
end;implementation{ Ta }procedure Ta.Test;
begin
ShowMessage('类a的代码');
end;{ Tb }procedure Tb.Test;
begin
inherited;
ShowMessage('类b的代码');
end;end.测试代码:unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MyClass, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var A1:Ta;
B1:Tb;
begin
A1:=Ta.Create;
A1.Test;
A1.Free;
B1:=Tb.Create;
B1.Test;
B1.Free
end;end.
这表示在当前类的当前方法执行时,首先执行父类中同名方法,然后再执行当前类的相关处理。
inherited关键字应用的场合多为实现类的多态用。如用于类的构建,一些界面的重绘等
inherited从字面上理解为“通过继承得到的,遗传的”,这只是其原意。引申到OOP中也就是上面所描述的意思了。
类似的代码为:TSomeObj.create(const AFlag:boolean);
begin
inherited;//---先执行父类的创建方法
。。在这里再执行其他的自定义操作。
end;