|
 |
栏目导栏 |
|
| |
|
|
|
|
 |
资料搜索 |
|
| |
|
|
|
|
 |
热门文章 |
|
| |
|
|
|
|
 |
最新文章 |
|
| |
|
|
|
| |
| |
|
|
|
|
动态创建控件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论坛讨论 |
|
|
|
|
|