自定义可折叠的控件属性的问题

renxucai 2008-12-03 02:33:33
如下代码:自定义控件的一个属性,希望把几个属性集中到一个条目下
点击前面的加号后,展开其内部的属性。
下面的程序,运行后在属性列表内有
+visibility,但是点击后下面没有内容,为什么?
——————————————————————————————————————————————————————
——————————————————————————————————————————————————————
unit SDProperty;

interface
uses SysUtils, Classes;
type Tvisibility=class(Tobject)
private
FVisible:boolean;
FVFrom:integer;
FVTo:integer;
procedure setvisible(value:boolean);
procedure setVFrom(value:integer);
procedure setVTo(value:integer);
protected
public
constructor create;
destructor destroy; override;
published
property Visible:boolean read Fvisible write setvisible default true;
property VFrom:integer read FVFrom write setVFrom default 0;
property VTo:integer read FVTo write setVTo default 0;

end;
//procedure Register;
Implementation
constructor TVisibility.create;
begin
Fvisible:=true;
FVFrom:=0;
FVTo:=0;
end;
destructor TVisibility.destroy;
begin
inherited;
end;
procedure TVisibility.setvisible(value:boolean);
begin
FVisible:=value;
end;
procedure Tvisibility.setVFrom(value:integer);
begin
FVFrom:=value;
end;
procedure TVisibility.setVTo(value:integer);
begin
FVTo:=value;
end;
end.

...全文
108 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
火龙岛主 2008-12-04
  • 打赏
  • 举报
回复
Tvisibility=class(Tobject) //这里应该是Tvisibility=class(TComponent)吧
private
FMyPro: TExPro;
procedure SetProperties(const Value: TExPro);
published
property MyPro:TExPro read FMyPro Write SetProperties;
//如果你不希望和TExPro的对象组合你应该这样
property MyPro:TExPro read FMyPro
并且一定要在constructor里面创建,在destructor里面销毁。

end;
kv2002 2008-12-04
  • 打赏
  • 举报
回复
TExPro = class(TPersistent)
private
FVisible:boolean;
FVFrom:integer;
FVTo:integer;
procedure setvisible(value:boolean);
procedure setVFrom(value:integer);
procedure setVTo(value:integer);
published
property Visible:boolean read Fvisible write setvisible default true;
property VFrom:integer read FVFrom write setVFrom default 0;
property VTo:integer read FVTo write setVTo default 0;
end;
Tvisibility=class(Tobject)
private
FMyPro: TExPro;
procedure SetProperties(const Value: TExPro);
published
property MyPro:TExPro read FMyPro Write SetProperties;
end;

大致是这样,看一下控件源码吧
renxucai 2008-12-04
  • 打赏
  • 举报
回复
无人问津么?
renxucai 2008-12-04
  • 打赏
  • 举报
回复
明白了。
我的问题是:自定义的属性类没有create,和free。
正如smallhand提及的。
我的属性类定义的已经很完整了,主要就是要在控件的create和destroy内把属性类给create出来。
是不是实例化呢?
renxucai 2008-12-04
  • 打赏
  • 举报
回复
上面两位老兄的回复没有看懂。
再说一下我的问题:
给控件增加一条属性,只要把一个属性字段放在published里面注明property,找到read write的方法就行了。
我想把几个属性集中在一个属性下面,点击这个属性前面的+号时,属性展开,可以查看设置子属性。
看delphi里Tpen,Tbrush,TFont,是这样的效果。看了半天,好像是这个类下面有好几条纪录,这几个类下面都是有定义handle。就不懂了。
不是很懂。谁可以用自定义的类实现以下,谢谢了
renxucai 2008-12-04
  • 打赏
  • 举报
回复
能不能给改的完整点
[Quote=引用 3 楼 SmallHand 的回复:]
Tvisibility=class(Tobject)  //这里应该是Tvisibility=class(TComponent)吧//这样的话这条属性前面的加号都没有了
private
FMyPro:  TExPro;
procedure  SetProperties(const  Value:  TExPro);
published
property  MyPro:TExPro  read  FMyPro  Write  SetProperties;
//如果你不希望和TExPro的对象组合你应该这样
property  MyPro:TExPro  read  FMyPro
并且一定要在constructor里面创建,在destructor里面销毁。
end;
[/Quote]

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧