是类引用。 看帮助相似的运用如下: A constructor can be called using a variable of a class-reference type. This allows construction of objects whose type isn抰 known at compile time. For example,type TControlClass = class of TControl; function CreateControl(ControlClass: TControlClass; const ControlName: string; X, Y, W, H: Integer): TControl; begin Result := ControlClass.Create(MainForm); with Result do begin Parent := MainForm; Name := ControlName; SetBounds(X, Y, W, H); Visible := True; end; end;The CreateControl function requires a class-reference parameter to tell it what kind of control to create. It uses this parameter to call the class抯 constructor. Because class-type identifiers denote class-reference values, a call to CreateControl can specify the identifier of the class to create an instance of. For example,CreateControl(TEdit, 'Edit1', 10, 10, 100, 20);Constructors called using class references are usually virtual. The constructor implementation activated by the call depends on the runtime type of the class reference.
1、“类之类”的类型,也就是所谓的“类引用”。 2、类这类可以直接调用类的“类方法”。 3、它只要用在类型参数化上,因为有时在编绎时无法得知某个对象的具体类型,而需要调用类方法(如构造函数),此时可以将类型作为参数来传递。 4、看Application.CreatForm(TFrom1,Form1); 可以得出 Type TComponentClass=Class of TComponent; //类引用类型 procedure TApplication.createform(instanceclass:TComponentClass;var Reference);
它的好处是在不知道子类类名的话也可以直接该子类的实例;
经典应用请参看Application.CreateForm函数。
看帮助相似的运用如下:
A constructor can be called using a variable of a class-reference type. This allows construction of objects whose type isn抰 known at compile time. For example,type TControlClass = class of TControl;
function CreateControl(ControlClass: TControlClass; const ControlName: string; X, Y, W, H: Integer): TControl;
begin
Result := ControlClass.Create(MainForm);
with Result do
begin
Parent := MainForm;
Name := ControlName;
SetBounds(X, Y, W, H);
Visible := True;
end;
end;The CreateControl function requires a class-reference parameter to tell it what kind of control to create. It uses this parameter to call the class抯 constructor. Because class-type identifiers denote class-reference values, a call to CreateControl can specify the identifier of the class to create an instance of. For example,CreateControl(TEdit, 'Edit1', 10, 10, 100, 20);Constructors called using class references are usually virtual. The constructor implementation activated by the call depends on the runtime type of the class reference.
2、类这类可以直接调用类的“类方法”。
3、它只要用在类型参数化上,因为有时在编绎时无法得知某个对象的具体类型,而需要调用类方法(如构造函数),此时可以将类型作为参数来传递。
4、看Application.CreatForm(TFrom1,Form1);
可以得出
Type TComponentClass=Class of TComponent; //类引用类型
procedure TApplication.createform(instanceclass:TComponentClass;var Reference);