delphi a=class(b);a:class(b)有什么区别

2025-02-23 05:48:02
推荐回答(3个)
回答1:

a= class(b)是类型声明,必须在type段中声明,表示a的类型信息继承自b,并且希望实现新的类方法等处理。如:
type
TFoo = class(TForm); //TFoo的类型声明继承自TForm
end;

a: b 表示a是b的类实例引用变量,一般在var或类结构的private/public中声明。
如:
type
TFoo = class(TForm); //TFoo的类型声明继承自TForm
private
ib: TButton; //表示ib是TButton的类实例引用变量
public
end;
又如:
procedure TForm1.Button1Click(Sender: TObject);
var
ib: TButton; //表示ib是TButton的类实例引用变量
begin
ib := TButton.Create(Self);

回答2:

a= class(b)是类型声明,必须在type段中声明,表示a的类型信息继承自b,并且希望实现新的类方法等处理。如:
type
TFoo = class(TForm); //TFoo的类型声明继承自TForm
end;

a: b 表示a是b的类实例引用变量,一般在var或类结构的private/public中声明。
如:
type
TFoo = class(TForm); //TFoo的类型声明继承自TForm
private
ib: TButton; //表示ib是TButton的类实例引用变量
public
end;
又如:
procedure TForm1.Button1Click(Sender: TObject);
var
ib: TButton; //表示ib是TButton的类实例引用变量
begin
ib := TButton.Create(Self);
...
end;

希望对你有所帮助。

回答3:

你说的不对