以下是从CoolControls中选择Copy过来的:
在注册的时候:
RegisterPropertyEditor(TypeInfo(TCCAboutBox), nil, '', TCCAboutProperty);
定义类:
TCCAboutBox = class
end;
定义属性编辑器:
{TCCAboutProperty}
TCCAboutProperty = class(TClassProperty)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function GetValue: string; override;
{$IFDEF VER130}
{$IFNDEF VER140}
procedure PropDrawName(ACanvas: TCanvas; const ARect: TRect;
ASelected: Boolean); override;
{$ENDIF}
{$ENDIF}
end;
定义属性编辑器成员函数实现:
procedure TCCAboutProperty.Edit;
begin
with TFormCoolAbout.Create(Application) do
try
LabelVersion.Caption := 'Version 2.08';
LabelText.Caption := GetComponent(0).ClassName + ' is one out of more than 45 components ' +
'from award winning CoolControls package.';
ShowModal;
finally
Free;
end;
end;
{$IFDEF VER130}
{$IFNDEF VER140}
procedure TCCAboutProperty.PropDrawName(ACanvas: TCanvas; const ARect: TRect;
ASelected: Boolean);
begin
ACanvas.Font.Style := [fsBold];
inherited PropDrawName(ACanvas, ARect, ASelected);
end;
{$ENDIF}
{$ENDIF}
function TCCAboutProperty.GetValue: string;
begin
Result := '(About)';
end;
自有类属性:
TCoolImages = class(TComponent)
private
FAboutBox: TCCAboutBox;
FClients: TList;
FBitmaps: TBitmaps;
protected
procedure Change; dynamic;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure RegisterChanges(Value: TCoolChangeLink);
procedure UnRegisterChanges(Value: TCoolChangeLink);
published
property About: TCCAboutBox read FAboutBox write FAboutBox;
property Bitmaps: TBitmaps read FBitmaps write FBitmaps;
end;