我在做VCL时的一个问题?请高手们班我解决一下(100分)

微程

Unregistered / Unconfirmed
GUEST, unregistred user!
我在做VCL的时候,做了一个属性,要做这此属性出现在 object inspector面板上,要如何操作,请给个例子!
 
将属性声明放在published中。
如果属性没有编辑器的话要自己作编辑器。
 
如何制作编辑器?
 
如:
Type
TMtEdit = class(TEdit)
private
FAbout: String;
procedure SetAbout(Value: String);
public
constructor Create(AOwner: TComponent); override;
published
property About: String read FAbout write SetAbout;

implementation

constructor TMyEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAbout := 'Contact me with my e-mail ...';
end;

procedure TMyEdit.SetAbout(Value: String);
begin
Value := 'Contact me with my e-mail ...';
if FAbout <> Value then
begin
FABout := Value;
invalidate;
end;
end;
 
type TAboutProperty = class(TPropertyEditor)
public
procedure Edit; override;
function GetValue: string; override;
function GetAttributes: TPropertyAttributes; override;
end;

delphi有一些现成的例子,你可以看看。
 
再问一下,哪个例子里面??
 
C:/Program Files/Borland/Delphi6/Source/Property Editors
有许多,比如picedit.pas
 
把特性声明在published,就可以让这个特性显示在对象观察
器上。
它的read与write分别是它的私有方法。这个私有方法应当与
某一个私有字段相联系的。
当这个特性被赋值时,实现上是调用对象写方法向这个私有变
段赋值,当对象的这个特性被赋值给其它变量时,实际上是调
用这个对象的读方法。把数据的读写用方法来实现,就可以实
现一些特殊的行为,如检查数据的合法性及进行其它的一些动
作。
 
顶部