一般定义类不同
TMyclass = class
private
.....
public
.....
end;
定义子类
TSonclass = class(TMyclass)
private
.....
public
.....
end;
类的抽象
Tclassclass = class of TMyclass;
实例:动态创建控件
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
1 unit Unit1;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, StdCtrls;
8
9 type
10 TMyclass = class of Tcontrol;
11 TForm1 = class(TForm)
12 Button1: TButton;
13 procedure Button1Click(Sender: TObject);
14 private
15 { Private declarations }
16 public
17 { Public declarations }
18 end;
19
20 var
21 Form1: TForm1;
22
23 implementation
24
25 {$R *.dfm}
26
27 function CreateCon(obj:TMyclass;Name1:string;x,y,w,h:integer):Tcontrol;
28
29 begin
30 result := obj.Create(Form1);
31 result.Parent := Form1;
32 result.Name := Name1;
33 result.SetBounds(x,y,w,h) ;
34 result.Visible := true;
35 end;
36
37 procedure TForm1.Button1Click(Sender: TObject);
38 begin
39 CreateCon(TEdit,'edit10',50,50,100,50);
40 end;
41
42 end