VCL控件属性编辑器类
来源:互联网 发布:ntfs for mac.dmg 编辑:程序博客网 时间:2024/06/05 15:59
在编写自己的控件过程中,在类中用__property定义的属性,系统会自动调用匹配的属性编辑器,如字符串、图片、字体等。当系统默认的属性编辑不符合应用的要求时,需要对属性编辑进行扩展。如需要选择一个文件或路径,此时VCL系统没有相应的编辑器。此时,只能通过继承TPropertyEditor类来进行扩展。
#include <designeditors.hpp>#include <DesignIntf.hpp>#include <vcleditors.hpp>//继承属性编辑器类class PACKAGE TMyPropertyEditor:public TPropertyEditor{ public: void __fastcall SetValue(const AnsiString Value); AnsiString __fastcall GetValue(); TPropertyAttributes __fastcall GetAttributes(); void __fastcall Edit(void); __fastcall TMyPropertyEditor(const _di_IDesigner ADesigner, int APropCount); __fastcall ~TMyPropertyEditor();};//覆盖父类方法:设置属性值void __fastcall TMyPropertyEditor::SetValue(const AnsiString Value){ ((TGraphicButtonControl1 * )GetComponent(0))->UIPicturePath->UIPath = Value; ((TGraphicButtonControl1 * )GetComponent(0))->SetUIPicPath(ExtractFilePath(Value));}//---------------------------------------------------------------------------//覆盖父类方法:获取属性值AnsiString __fastcall TMyPropertyEditor::GetValue(){ AnsiString tmpS=((TGraphicButtonControl1 * )GetComponent(0))->UIPicturePath->UIPath; ((TGraphicButtonControl1 * )GetComponent(0))->SetUIPicPath(ExtractFilePath(tmpS)); return tmpS;}//---------------------------------------------------------------------------__fastcall TMyPropertyEditor::TMyPropertyEditor(const _di_IDesigner ADesigner, int APropCount):TPropertyEditor(ADesigner,APropCount){ }//---------------------------------------------------------------------------__fastcall TMyPropertyEditor::~TMyPropertyEditor(){ //TODO: Add your source code here}//---------------------------------------------------------------------------//修改属性,弹出对话框TPropertyAttributes __fastcall TMyPropertyEditor::GetAttributes(){ return TPropertyAttributes()<<paDialog;}//---------------------------------------------------------------------------//通过对话框修改属性void __fastcall TMyPropertyEditor::Edit(void){ TOpenDialog * dg = new TOpenDialog(0); if(dg->Execute()) { ((TGraphicButtonControl1 * )GetComponent(0))->UIPicturePath->UIPath = ExtractFilePath(dg->FileName); ((TGraphicButtonControl1 * )GetComponent(0))->SetUIPicPath(ExtractFilePath(dg->FileName)); }}//---------------------------------------------------------------------------//将特殊的属性字段封装到一个VCL类中,才能在控件的Register()函数中注册class TMyFile : public TPersistent{ AnsiString FFilePath;//这是文件路径,我们要用到的扩展属性 public: TMyFile() { ; } __published: __property AnsiString UIPath = {read = FFilePath,write = FFilePath};};控件的.cpp文件中注册过程如下:namespace Graphicbuttoncontrol1{ void __fastcall PACKAGE Register() { //注册控件 TComponentClass classes[1] = {__classid(TGraphicButtonControl1)}; RegisterComponents("Samples", classes, 0); //注册属性编辑器 RegisterPropertyEditor( __typeinfo(TMyFile),//注意:自定义的封装类 __classid(TGraphicButtonControl1),//控件类 "UIPicturePath",//控件的属性字体,能在IDE中可视编辑 __classid(TMyPropertyEditor)//继承来的属性编辑类 ); }}编译控件的时候,在bpk工程的requires下添加designide.bpi
0 0
- VCL控件属性编辑器类
- VCL (三) 属性编辑器
- VCL (三) 属性编辑器
- VCL (三) 属性编辑器
- VCL 按钮类控件
- vcl控件常用属性和方法
- vcl控件常用属性和方法
- vcl控件常用属性和方法
- C#控件开发---控件属性编辑器
- C#控件开发---控件属性编辑器
- VCL 控件分类
- Vcl控件详解
- VCL控件之Label
- 设置自定义控件集合编辑器属性
- VCL组件之Name属性
- VCL解压缩控件使用例子
- .NET ActiveX VCL控件仓库
- VCL组件之编辑控件
- hdu-1513 Palindrome vs nyoj-37 回文字符串
- 玩日期时间
- unity之飞机大战
- spring security3.x学习(23)_session管理和session监听
- combination
- VCL控件属性编辑器类
- 第八周任务----Flask框架的学习
- 喷水装置
- linux c/c++ GDB教程详解
- OC-遍历集合类
- spring security3.x学习(24)_拒绝访问异常处理(AccessDeniedException)
- Spark GraphX 入门实例完整scala代码
- date.gettime()返回的是什么?
- 第十七周项目四—生日差几天