标签:代码 get only written readonly rop 编辑 漂亮 rms
Delphi所提供的TStatusBar可视化控件可以让我们快速地实现状态条。然而Delphi自带的TStatusBar创建的状态条仅能显示文字。本文介绍如何在Delphi程序中创建更为漂亮的StatusBar。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控件,我们可以非常容易地在StatusBar上增添其它的内容了。比如,如果想要在状态条上显示一个图片,只要在TStatusBarEx控件上放一个Image控件;想要添加一个进度条,只需在上面加一个ProgressBar就行了!
1.加入搜索路径
C:\Program Files\Borland\Delphi7\Source\ToolsAPI
2.打开
C:\Program Files\Borland\Delphi7\Source\ToolsAPI\DesignEditors.pas
3.找到并把
uses
Types, SysUtils, Classes, TypInfo, Variants, DesignIntf, DesignMenus,Proxies;改为
uses
Types, SysUtils, Classes, TypInfo, Variants, DesignIntf, DesignMenus{,Proxies};
4.找到并把
if (FAncestor = nil) and (Component <> Designer.Root)
and IsProxyClass(Component.ClassType) then
改为
if (FAncestor = nil) and (Component <> Designer.Root)
{and IsProxyClass(Component.ClassType)} then
5.找到并把
while IsProxyClass(ComponentClass) do
改为
//while IsProxyClass(ComponentClass) do
6.保存,编译运行,OK
上面3.4.5.就是把Proxies单元从DesignEditors单元中剔除,DesignEditors单元
中只有两个地方引用了Proxies单元的函数,而且是同一个函数:IsProxyClass,把
这两个地方注释掉就可以了.
标签:代码 get only written readonly rop 编辑 漂亮 rms
原文地址:https://blog.51cto.com/alun51cto/2508912