请教小问题一个,代码如下://========================
//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.
解决方案 »
- 北京、广州、西安我该如何选择?
- 改变ComboBox的值时如何改变其他的Edit的值?
- 有关向服务器端网页通过Navigate传送文件的问题,急,up有分
- 如没有知道数字滤波的朋友?
- CommInt??是什么??程序中use了这个东东,可编译时说找不到Commint.dcu!!
- 谁知道<<delphi 5企业级解决方案及应用剖析>>的范例代码哪里下载?
- 进货单问题.
- 求助。。。学生成绩管理(源代码)。。。初学者还不懂。。。需高手指教。。。
- -------Paradox7支持回滚吗?-------
- 各位同志:有谁能告诉我该如何在pradox里存入jpeg图象文件
- 条码打印问题
- 初学者问题:数组怎么作为参数进行传递?
//1,创建派生类的时候,基类也创建了。今天恰好崩到这个问题//2, 基类,派生类加个构造函数,ShowMessage 看下,什么都知道了。
楼主一次搞了这么多类,不怕罚款...
procedure xx(a, b: Integer);是个静态的方法,
如果把这个方法后面加个virtual,如下:
procedure xx(a, b: Integer);virtual;
再用aaa1.xx(4, 4);就会出错了,呵呵!