A
apple4123
Unregistered / Unconfirmed
GUEST, unregistred user!
高手指点:
我在网上找到这个,想实现,可总出现问题。我把源代码呈现给大家。大家一起来讨论。
---- 以下是实现TStatusBarEx控件的Delphi源代码,请把这段代码拷贝下来,并且将其保存到文件StatusBarEx.PAS中去。然后用Delphi打开StatusBarEx.PAS文件,之后选择“Component | Install Component …”,将TStatusBarEx控件安装。
//文件名:StatusBarEx.pas
unit StatusBarEx;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, ComCtrls, DsgnIntf;
type
//定义About属性的属性编辑器
TAbout = class(TPropertyEditor)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function Getvalue: string; override;
end;
//定义TStatusBarEx控件
TStatusBarEx = class(TStatusBar)
private
{ Private declarations }
Fabout:TAbout;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
property about: TAbout read FAbout;
end;
procedure Register;
implementation
constructor TStatusBarEx.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{为了让TStatusBarEx控件能接受其它控件,必须
使ControlStyle属性(集合类型)包含csAcceptsControls元素}
ControlStyle:= ControlStyle + [csAcceptsControls];
end;
//以下是TAbout中的成员函数的实现
procedure TAbout.Edit;
begin
Application.MessageBox('TStatusBarEx for Delphi 5'#13#10
+'Written by Simon Liu'#13#10
+'Email:simon_liu@263.net',
'About TStatusBarEx',MB_ICONINFORMATION);
end;
function TAbout.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paReadOnly];
end;
function TAbout.Getvalue: string;
begin
Result := '(Simon)';
end;
procedure Register;
begin
//将TStatusBarEx控件注册到Delphi 5控件板的Win32页上
RegisterComponents('Win32', [TStatusBarEx]);
//为About属性注册属性编辑器
RegisterPropertyEditor(typeInfo(TAbout), TStatusBar,
'About', TAbout);
end;
end.
我在网上找到这个,想实现,可总出现问题。我把源代码呈现给大家。大家一起来讨论。
---- 以下是实现TStatusBarEx控件的Delphi源代码,请把这段代码拷贝下来,并且将其保存到文件StatusBarEx.PAS中去。然后用Delphi打开StatusBarEx.PAS文件,之后选择“Component | Install Component …”,将TStatusBarEx控件安装。
//文件名:StatusBarEx.pas
unit StatusBarEx;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, ComCtrls, DsgnIntf;
type
//定义About属性的属性编辑器
TAbout = class(TPropertyEditor)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function Getvalue: string; override;
end;
//定义TStatusBarEx控件
TStatusBarEx = class(TStatusBar)
private
{ Private declarations }
Fabout:TAbout;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
property about: TAbout read FAbout;
end;
procedure Register;
implementation
constructor TStatusBarEx.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{为了让TStatusBarEx控件能接受其它控件,必须
使ControlStyle属性(集合类型)包含csAcceptsControls元素}
ControlStyle:= ControlStyle + [csAcceptsControls];
end;
//以下是TAbout中的成员函数的实现
procedure TAbout.Edit;
begin
Application.MessageBox('TStatusBarEx for Delphi 5'#13#10
+'Written by Simon Liu'#13#10
+'Email:simon_liu@263.net',
'About TStatusBarEx',MB_ICONINFORMATION);
end;
function TAbout.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paReadOnly];
end;
function TAbout.Getvalue: string;
begin
Result := '(Simon)';
end;
procedure Register;
begin
//将TStatusBarEx控件注册到Delphi 5控件板的Win32页上
RegisterComponents('Win32', [TStatusBarEx]);
//为About属性注册属性编辑器
RegisterPropertyEditor(typeInfo(TAbout), TStatusBar,
'About', TAbout);
end;
end.