【delphi】常见类的定义方法!

一般定义类不同

TMyclass = class

private

.....

public

.....

end;

定义子类

TSonclass = class(TMyclass)

private

.....

public

.....

end;

 

类的抽象

Tclassclass = class of TMyclass;

 

实例:动态创建控件

ContractedBlock.gif ExpandedBlockStart.gif Code
 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

 

posted on 2009-05-13 17:34 2005大懒虫 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/flying_heart/archive/2009/05/13/1456109.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值