class of classname :类引用.常用来创建未确定类名的对象 class function :类方法,可不创建对象而直接可以用类调用的方法
calss of 有点象系列的意思,帮助里的例子很能说明问题,TControl系列都可以。type TControlClass = class of TControl;function CreateControl(ControlClass: TControlClass; const ControlName: string; X, Y, W, H: Integer): TControl; begin Result := ControlClass.Create(Application.MainForm); with Result do begin Parent := Application.MainForm; Name := ControlName; SetBounds(X, Y, W, H); Visible := True; end; end; procedure TForm1.Button1Click(Sender: TObject); begin CreateControl(TEdit, 'Edit1', 10, 10, 100, 20); CreateControl(TLabel, 'Label1', 10, 40, 100, 20); end;class function 是不用创建对象实例就可以调用的方法,叫做类方法。
type TformCLass=Class of Tformtype TmyClass=class private aname:string; public class procedure showinfo; end;var aclass:Tmyclass; procedure Tmyclass.showinfo; begin showmessage(aname); end;class of :类之类,是类的引用,多用在一些要动态创建控件或组件,但有不确定类型的场合下用类引用类型作为要创建的控件或组件的一个容器; class procedure (function):是指一种操作类的方法;在不要创建类实例的情况下,可直接操作类。
class function :类方法,可不创建对象而直接可以用类调用的方法
const ControlName: string; X, Y, W, H: Integer): TControl;
begin
Result := ControlClass.Create(Application.MainForm);
with Result do
begin
Parent := Application.MainForm;
Name := ControlName;
SetBounds(X, Y, W, H);
Visible := True;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
CreateControl(TEdit, 'Edit1', 10, 10, 100, 20);
CreateControl(TLabel, 'Label1', 10, 40, 100, 20);
end;class function
是不用创建对象实例就可以调用的方法,叫做类方法。
TformCLass=Class of Tformtype
TmyClass=class
private
aname:string;
public
class procedure showinfo;
end;var
aclass:Tmyclass;
procedure Tmyclass.showinfo;
begin
showmessage(aname);
end;class of :类之类,是类的引用,多用在一些要动态创建控件或组件,但有不确定类型的场合下用类引用类型作为要创建的控件或组件的一个容器;
class procedure (function):是指一种操作类的方法;在不要创建类实例的情况下,可直接操作类。