如何编写控件的属性,使其在设计阶段可以输入(100分)

W

wangts

Unregistered / Unconfirmed
GUEST, unregistred user!
某控件的一 published property 类型为记录或链表型,
在使用这控件时,希望在 object inspector中弹出一对话框
输入其控件属性,类似TStatusBar 的Panels属性。
自己编写的控件如何实现此功能,
请赐教,希望有源程序的例子
 
你将此属性设为TStrings或TStringList,实现时用TStringList,
Delphi自动将为你提供一个对话框让你输入多行的值,象
TComboBox.Items那样。不过别忘了TStringList的Create和
Free喔,不然you will go to hell!
 
多谢赐教。
但,仅仅能输入多行的值是不够的,属性可能是一记录类型,或记录类型的
链表,如何自定义对话框并在 object inspector 中使用它。
 
兄弟,这是我从TPanel继承下来的一个东东,没有实际价值,但
是可以为你排忧解难,新加入了一个Items属性。

type
tpanel1 = class(tpanel)
private
{ Private declarations }
PItems : TStrings;
procedure SetPItems(Value : TStrings);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner : TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
property Items : TStrings read PItems write SetPItems;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [tpanel1]);
end;

constructor TPanel1.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
PItems := TStringList.Create; //TStrings为虚类,所以实现时
//要用TStringList
end;

destructor TPanel1.Destroy;
var
I : integer;
begin
for I := 0 to PItems.Count - 1 do begin
TPanel(PItems.Objects).Free;
end;
PItems.Free;
inherited Destroy; //Free不行!
end;

procedure TPanel1.SetPItems(Value : TStrings);
begin
PItems.Assign(Value); //不能写PItems := Value
end;


给分?
 
对不起,发送时没有看到你的新要求。

如果非要在object inspector 中添加你的记录型属性,
我看只有自己做一个Property-Editor了。
其实动态添加记录指针也不错。
 
继承TCollectionItem 和TCollection可以轻松做到.用法可以看Delphi的源程序.
 
多谢指点。
 
能否用属性编辑器的注册来解决这个问题?
 

Similar threads

顶部