unit Unit1;
interface
uses
Classes, Controls, Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
TBase = class
procedure proc1; virtual;
procedure proc2;
end;
TChild = class(TBase)
procedure proc1; override;
procedure proc2;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TBase }
procedure TBase.proc1;
begin
ShowMessage('B1');
end;
procedure TBase.proc2;
begin
ShowMessage('B2');
end;
{ TChild }
procedure TChild.proc1;
begin
//inherited;
ShowMessage('C1');
end;
procedure TChild.proc2;
begin
ShowMessage('C2');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
B: TBase;
C: TChild;
BC: TBase;
begin
B := TBase.Create;
C := TChild.Create;
BC := TChild.Create;
B.proc1; //B1
B.proc2; //B2
TChild(B).proc1; //B1
TChild(B).proc2; //C2
C.proc1; //C1
C.proc2; //C2
TBase(C).proc1; //C1
TBase(C).proc2; //B2
BC.proc1; //C1
BC.proc2; //B2
TBase(BC).proc1; //C1
TBase(BC).proc2; //B2
TChild(BC).proc1; //C1
TChild(BC).proc2; //C2
B.Free;
C.Free;
BC.Free;
end;
end.
Delphi类的入门的例子(5): override
时间: 2024-11-03 10:37:03
Delphi类的入门的例子(5): override的相关文章
Delphi类的入门的例子(6): 类引用示例
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) RadioGroup1: TRadioGroup; procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shi
Delphi类的入门例子(3): Create与Destroy
//类单元unit Person; interface uses Dialogs; type TPerson = class(TObject) private FName: string; FAge: Integer; public constructor Create(strName: string; intAge: Integer); destructor Destroy; override; function GetName: string; function GetAge: Intege
Delphi类的入门例子(9): 获取对象的 RTTI 属性与事件的函数
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, xmldom, XMLIntf, XMLBrokr, msxmldom, XMLDoc; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Memo1: TMemo; Memo2:
Delphi类的入门例子(7): 遍历窗体的所有父类
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; procedure Button1Click(Sender:
Delphi类的入门例子(4): property
//类单元unit Person; interface type TPerson = class(TObject) private FName: string; FAge: Integer; public procedure SetName(const strName: string); procedure SetAge(const intAge: Integer); property Name: string read FName write SetName; property Age: In
Delphi类的入门例子(2): 数字盒子
//类单元 unit NumBox; interface type TNumBox = class private FCount: Integer; public procedure AddOne; procedure AddFive; procedure ZeroCount; function GetCount: Integer; end; implementation { TNumBox } procedure TNumBox.AddOne; begin Inc(FCount); end;
Delphi类的入门例子(8): 遍历窗体中所有控件的函数
//显示窗体中所有控件的函数 function GetCtrls(Control: TWinControl; List: TStringList): Boolean; var i: Integer; obj: TWinControl; begin for i := 0 to Control.ControlCount-1 do begin obj := TWinControl(Control.Controls[i]); List.Add(obj.Name); //如果控件中包含其他控件, 则递归调
Delphi类的的入门例子(1): 继承窗体
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Se
Android中的ViewPager视图滑动切换类的入门实例教程_Android
ViewPager引入示例首先让大家有个全局的认识,直接上个项目,看看仅仅通过这几行代码,竟然就能完成如此强悍的功能. 效果图: 实现了三个view间的相互滑动. 第一个VIEW向第二个VIEW滑动.第二个VIEW向第三个VIEW滑动 一.新建项目,引入ViewPager控件ViewPager.它是google SDk中自带的一个附加包的一个类,可以用来实现屏幕间的切换. 1.在主布局文件里加入 <RelativeLayout xmlns:android="http://schemas.a