对delphi的Create,inherited,AfterConstruction的流程了解及测试
来源:互联网 发布:数据备份方案 编辑:程序博客网 时间:2024/05/22 03:47
写了一个测试代码, 创建一个窗体拉上一个按钮控件,复制以下的代码
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- C1 = class //(TPersistent)
- private
- p1:string;
- public
- procedure Show;
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- constructor Create; virtual;
- procedure test(str: string);
- end;
- C2 = class(C1)
- public
- constructor Create; override;
- constructor CreateNew; virtual;
- procedure AfterConstruction; override;
- procedure Show;
- end;
- C3 = class(c2)
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- { C1 }
- procedure C1.AfterConstruction;
- begin
- inherited AfterConstruction;
- test('C1.AfterConstruction'); ;
- end;
- procedure C1.BeforeDestruction;
- begin
- test('C1.BeforeDestruction'); ;
- inherited BeforeDestruction;
- end;
- constructor C1.Create;
- begin
- inherited;
- test('C1.Create');
- end;
- procedure C1.Show;
- begin
- ShowMessage(p1);
- end;
- procedure C1.test(str: string);
- begin
- ShowMessage(str);
- end;
- { C2 }
- procedure C2.AfterConstruction;
- begin
- inherited;
- ShowMessage('C2.AfterConstruction');
- end;
- constructor C2.Create;
- begin
- inherited Create;
- test('c2.Create'); ;
- end;
- constructor C2.CreateNew;
- begin
- Create;
- test('c2.CreateNew');
- end;
- procedure C2.Show;
- begin
- inherited Show;
- test('c2.show');
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- var
- a: c3;
- b: c2;
- c:c1;
- begin
- c:=c3.CreateNew;
- c.p1:='aaa';
- c.Show;
- c.test('aaaaa');
- end;
- end.
单击按钮时,依次显示:
C1.Create // 运行了c:=c3.CreateNew; inherited Create;
C2.Create //Create;
C2.CreateNew
C1.AfterConstruction C2.AfterConstruction 里的inherited
C2.AfterConstruction
aaa
aaaaa
在对象创建前会自动调用AfterConstruction,资料参考空间里之前发布的文章
- 对delphi的Create,inherited,AfterConstruction的流程了解及测试
- 对inherited的一点理解
- Delphi中inherited的详细用法
- 请描述你对测试的了解, 内容可以涉及测试流程, 测试类型, 测试方法, 测试工具等。
- 测试一下你对指针的了解
- 谈谈对移动app测试的了解
- 测试的流程及测试职责
- 对Java数组的了解及认识
- java注解的Inherited
- Inherited继承的练习
- CCSprite的Create流程--MD
- 软件测试的目的、原则及流程
- 移动APP的测试流程及方法
- 全面了解 Cookie的传递流程、编程实现及安全问题
- 全面了解 Cookie的传递流程、编程实现及安全问题
- 全面了解Cookie的传递流程、编程实现及安全问题
- 了解数据存储mysql对测试的助益
- Insert into select 与create table as的性能测试及create table
- BMP文件格式分析
- 设计CDib类
- Memcache协议中文版
- WinCE中的Debug Zone调试
- 在ACCESS 中调用后台存储过程
- 对delphi的Create,inherited,AfterConstruction的流程了解及测试
- Building a JavaFX Application Using NetBeans IDE
- 算法设计方法(一) —— 贪心法
- 浅谈PHP缓存技术之二
- VB实现SQL Server 2000存储过程调用
- 多线程学习笔记 四
- LINUX下ORACLE安装
- SummaryInformation 流格式
- MySQL基本命令