请教小问题一个,代码如下://========================
//aaa1:= Taaa.Create;
aaa1.xx(4, 4);
//========================
aaa1这个对象,我如果不 create他,为什么都可以用,应该会出错啊?是个空指针啊。unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; Taaa = class
procedure xx(a, b: Integer);
end; Taa1 = class(Taaa)
procedure xx(a, b: Integer);
end;var
Form1: TForm1;
c: Integer;
aaa1: Taaa;implementation{$R *.dfm}{ Taaa }procedure Taaa.xx(a, b: Integer);
begin
c:= a - b;
end;{ Taa1 }procedure Taa1.xx(a, b: Integer);
begin
c:= a + b;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
//aaa1:= Taaa.Create;
aaa1.xx(4, 4);
showmessage(inttostr(c));
end;end.
//aaa1:= Taaa.Create;
aaa1.xx(4, 4);
//========================
aaa1这个对象,我如果不 create他,为什么都可以用,应该会出错啊?是个空指针啊。unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; Taaa = class
procedure xx(a, b: Integer);
end; Taa1 = class(Taaa)
procedure xx(a, b: Integer);
end;var
Form1: TForm1;
c: Integer;
aaa1: Taaa;implementation{$R *.dfm}{ Taaa }procedure Taaa.xx(a, b: Integer);
begin
c:= a - b;
end;{ Taa1 }procedure Taa1.xx(a, b: Integer);
begin
c:= a + b;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
//aaa1:= Taaa.Create;
aaa1.xx(4, 4);
showmessage(inttostr(c));
end;end.
解决方案 »
- 如何发布C/S两层数据库?
- 谁能帮帮我,都急死了,关于tSimpleDataSet.ApplyUpdates
- 如何在DBGrid中加入序号,我用的是Oracle, ADO
- 有谁的信誉分比我低阿!!我送给他50分阿!!
- 我很菜,問一下dll的問題,保存時將文件名定為testdll.dll,再打開時說Error loading...,具體請見內,100分.
- 关于treeview的问题?
- 请求帮助,高分赠送
- 有没有用delphi,OpenGL实现的迷宫之类的源码?
- 用dbgrid或stringgrid组件制作动态查询(急!!!)
- 北京上地,诚聘delphi开发工程师
- 条码打印问题
- 初学者问题:数组怎么作为参数进行传递?
//1,创建派生类的时候,基类也创建了。今天恰好崩到这个问题//2, 基类,派生类加个构造函数,ShowMessage 看下,什么都知道了。
楼主一次搞了这么多类,不怕罚款...
procedure xx(a, b: Integer);是个静态的方法,
如果把这个方法后面加个virtual,如下:
procedure xx(a, b: Integer);virtual;
再用aaa1.xx(4, 4);就会出错了,呵呵!