在DELPHI中编写控件,如何定义一个新的属性类型,来实现自己的目的?(100分)

  • 主题发起人 主题发起人 BILLYZHENG
  • 开始时间 开始时间
B

BILLYZHENG

Unregistered / Unconfirmed
GUEST, unregistred user!
例如有的控件在DELPHI的IDE中的属性窗口中加上作者的信息或者双击控件弹出关于窗口等。
 
以下是从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;

 
再学习~~~再关注~~~~~
 

Similar threads

后退
顶部