自编可视化组件,怎么在自定义的属性里显示个按钮,点击后弹出个对话框?
自编可视化组件,怎么在自定义的属性里显示个按钮,点击后弹出个对话框?就像TTreeView组件里的Items属性一样,在设计期,在Object Inspector里一点Items属性,右边出个按钮,一点弹出个TreeView Items Editor对话框可在里面添加节点,多谢各位大侠回贴 问题点数:100、回复次数:5Top
1 楼constantine(飘遥的安吉儿)回复于 2005-11-18 12:12:49 得分 50
http://www.programfan.com/article/showarticle.asp?id=2566
这个你看看是不是对你有用delphi的Top
2 楼constantine(飘遥的安吉儿)回复于 2005-11-18 12:24:47 得分 0
实际上你的情况应该开发多一个设计期包,把属性编辑器放在里面Top
3 楼cczlp(不惑)回复于 2005-11-18 13:53:30 得分 50
提供一个简单的例子:
MyEdit.h
====
//---------------------------------------------------------------------------
#ifndef MyEditH
#define MyEditH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include "DesignEditors.hpp"
//---------------------------------------------------------------------------
class TMyText : public TPersistent
{
private:
AnsiString FMyText;
__published:
__property AnsiString MyText = {read = FMyText, write = FMyText};
};
//---------------------------------------------------------------------------
class PACKAGE TMyEditor : public TPropertyEditor
{
protected:
TPropertyAttributes __fastcall GetAttributes(void);
void __fastcall Edit(void);
public:
__fastcall TMyEditor(const _di_IDesigner ADesigner,
int APropCount);
// __fastcall ~TMyEditor();
};
//---------------------------------------------------------------------------
class PACKAGE TMyEdit : public TCustomEdit
{
private:
TMyText *FNewText;
protected:
public:
__fastcall TMyEdit(TComponent* Owner);
__fastcall ~TMyEdit();
__published:
__property TMyText *NewText = {read = FNewText, write = FNewText};
};
//---------------------------------------------------------------------------
#endif
Top
4 楼cczlp(不惑)回复于 2005-11-18 13:53:46 得分 0
MyEdit.cpp
===========
//---------------------------------------------------------------------------
//编译时在Requires中添加designdgm.bpi, designide.bpi
#include <vcl.h>
#pragma hdrstop
#include "MyEdit.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TMyEdit *)
{
new TMyEdit(NULL);
}
//---------------------------------------------------------------------------
__fastcall TMyEdit::TMyEdit(TComponent* Owner)
: TCustomEdit(Owner)
{
NewText = new TMyText;
}
//---------------------------------------------------------------------------
__fastcall TMyEdit:: ~TMyEdit()
{
delete NewText;
}
//---------------------------------------------------------------------------
namespace Myedit
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TMyEdit)};
RegisterComponents("Standard", classes, 0);
TTypeInfo tk;
tk.Kind = tkString;
tk.Name = "AnsiString";
RegisterPropertyEditor(__typeinfo(TMyText), __classid(TMyEdit),
"NewText", __classid(TMyEditor));
}
}
//---------------------------------------------------------------------------
__fastcall TMyEditor::TMyEditor(const _di_IDesigner ADesigner, int APropCount)
: TPropertyEditor(ADesigner, APropCount)
{
}
//---------------------------------------------------------------------------
//具有...
TPropertyAttributes __fastcall TMyEditor::GetAttributes(void)
{
return TPropertyAttributes()<<paDialog;
}
//---------------------------------------------------------------------------
//显示对话框
void __fastcall TMyEditor::Edit(void)
{
((TMyEdit *)GetComponent(0))->NewText->MyText =
InputBox("Input text", "NewText", ((TMyEdit *)GetComponent(0))->NewText->MyText);
}
//---------------------------------------------------------------------------
Top
5 楼zzhong2()回复于 2005-12-04 12:14:12 得分 0
多谢楼上两位大侠,结贴晚了点,海涵海涵Top




