linux社区爱心援助Linux认证系列教程业界动态站务新闻公司招聘网络学院网址大全LPI专题CISCO专题
设为首页
加入收藏
管理团队
JSP  
JAVA  
PERL  
 您的位置:首页 > 开发语言 > Delphi >
栏目导栏
  php
  JSP
  ASP
  asp.net
  JAVA
  c/c++/c#
  perl
  JavaScript
  Basic
  Delphi
资料搜索
热门文章
·HexToStr函数和StrToHex函数
·Delphi中的进制转换
·delphi轻松设置无边框透明窗体
·delphi第三方控件安装(Ehlib)
·DELPHI组件安装全攻略
·delphi动态创建控件
·开发工具比较Visual C++ VS De
·delphi完整身份证效验程序实例
·delphi中的Format函数详解
·delphi编程获取打印机的打印任
·如何判断文本文件的编码格式
·深入研究Variant数组
·用delphi编写网络游戏的外挂
·Delphi技巧-用户自定义数据类型
·delphi设置控件透明
最新文章
·在应用程序中跟踪MOUSE的坐标
·压缩和修复MS Access 2000文件
·DELPHI 6.0 动画制做
·怎样在Delphi中调用LastError信
·怎样得到主域服务器名称
·怎样利用递归实现删除某一目录
·读出主键下所有项
·如何制作照片底片效果的图像(
·获得Modem的状态
·WebBrowser屏幕滚动的实现,设
·有关字符串处理的小技巧
·Delphi建立键盘鼠标动作纪录与
·Delphi中布尔类型辨析
·DELPHI程序注册码设计
·图形的不规则的Copy
Google
 
delphi动态创建控件
[ 作者:  加入时间:2007-10-30 15:07:56  来自:Linux联盟收集整理 ]
动态创建控件FSULinux联盟
FSULinux联盟
其实动态创建控件很简单,相信看过本文后你会全明白的。FSULinux联盟
FSULinux联盟
1 先在单元的initialization 部分注册它,(这样在单元使用时会自动注册的)如:FSULinux联盟
FSULinux联盟
RegisterClass( TButton );
FSULinux联盟
2 使用FindClass 或 GetClass函数取得类参考,如:FSULinux联盟
FSULinux联盟
var MetaClass : TPersistentClass; FSULinux联盟
MetaClass := FindClass( 'TForm2');
FSULinux联盟
3 映射MetaClass为一般类型,否则你不能调用正确的constructor (因为你没指明所需参数)FSULinux联盟
FSULinux联盟
var ComponentMetaClass : TComponentClass;FSULinux联盟
ComponentMetaClass := TComponentClass( MetaClass );
FSULinux联盟
FSULinux联盟
4 调用constructor FSULinux联盟
FSULinux联盟
var AForm: TComponent;FSULinux联盟
AForm := ComponentMetaClass.Create( self );
FSULinux联盟
5 AForm 现在成为一个有效的类实例,可以调用它的方法了。FSULinux联盟
FSULinux联盟
TForm(AForm).Show;
FSULinux联盟
FSULinux联盟
FSULinux联盟
var SomeForm : TForm;FSULinux联盟
SomeForm := TForm( AForm );FSULinux联盟
SomeForm.Show;
FSULinux联盟
完整示例:FSULinux联盟
FSULinux联盟
procedure TForm1.Button1Click(Sender: TObject); FSULinux联盟
var MetaClass : TPersistentClass;FSULinux联盟
ComponentMetaClass : TComponentClass;FSULinux联盟
AForm: TComponent;FSULinux联盟
beginFSULinux联盟
  MetaClass := FindClass( 'TForm2');FSULinux联盟
  ComponentMetaClass := TComponentClass( MetaClass );FSULinux联盟
  AForm := ComponentMetaClass.Create( self ); FSULinux联盟
  TForm(AForm).Show;FSULinux联盟
end;
FSULinux联盟
或者是FSULinux联盟
TFormTForm( TComponentClass( FindClass( 'TForm2' ) ).Create( Self )).Show;
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·Delphi实现远程串口的数据采集  (2007-10-30 16:10:39)
 ·Delphi托盘编程实战演练  (2007-10-30 16:09:56)
 ·DELPHI中操作ACCESS技巧集  (2007-10-30 16:08:48)
 ·在DELPHI中打印TDBGrid内容  (2007-10-30 16:05:41)
 ·在Delphi 2005中安装组件  (2007-10-30 16:04:02)
 ·DELPHI组件安装全攻略  (2007-10-30 15:54:19)
 ·Delphi中树型控件的使用技巧  (2007-10-30 15:41:50)
 ·在DELPHI中用线程排序  (2007-10-30 15:41:06)
 ·Delphi的嵌入式asm: Byte快速转换为16进制  (2007-10-30 15:40:20)
 ·创建一个简单的Delphi专家  (2007-10-30 15:14:08)