Delphi 我需要关于如何实现可以在对象检查器中显示的类的帮助
我有 我希望在Object Insectt中显示此功能来编辑设置 我尝试添加Delphi 我需要关于如何实现可以在对象检查器中显示的类的帮助,delphi,class,object,properties,custom-component,Delphi,Class,Object,Properties,Custom Component,我有 我希望在Object Insectt中显示此功能来编辑设置 我尝试添加 ... TDispPitch = class private iLineSize: Integer; iLineColor: TColor; bDisplayAccent: Boolean; bVisible: Boolean; published property LineSize : Integer read iLineSize write iLineSize;
...
TDispPitch = class
private
iLineSize: Integer;
iLineColor: TColor;
bDisplayAccent: Boolean;
bVisible: Boolean;
published
property LineSize : Integer read iLineSize write iLineSize;
...etc
end;
...
可以显示DispPitch,但我看不到它的属性。与LineSize、LineColor等类似。您必须从
t持久的
或子体派生类,以便使其在对象检查器中可用:
property DispPitch: TDispPitch read FDispPitch write FDispPitch. like
来自Delphi文档:
持久是所有人的祖先
具有赋值和
流媒体功能
该类需要从
TPersistent
派生,并应实现Assign()(或AssignTo())方法,以及公开OnChange
事件,以便包含的类可以对更改做出反应,例如:
TDispPitch = class(TPersistent)
private
...
published
property ...
...
end;
您还需要重写
TPersistent.Assign()
方法,然后让包含类的属性使用调用Assign()的setter方法,而不是直接指定其字段指针。看看我的另一个答案。
type
TDispPitch = class(TPersistent)
private
iLineSize: Integer;
iLineColor: TColor;
bDisplayAccent: Boolean;
bVisible: Boolean;
FOnChange: TNotifyEvent;
procedure Changed;
procedure SetLineSize(Value : Integer);
procedure SetLineColor(Value: TColor);
procedure SetDisplayAccent(Value: Boolean);
procedure SetVisible(Value: Boolean);
public
procedure Assign(Source: TPersistent); override;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
published
property LineSize : Integer read iLineSize write SetLineSize;
property LineColor: TColor read iLineColor write SetLineColor;
property DisplayAccent: Boolean read bDisplayAccent write SetDisplayAccent;
property Visible: Boolean read bVisible write SetVisible;
end;
procedure TDispPitch.Assign(Source: TPersistent);
var
LSource: TDispPitch;
begin
if Source is TDispPitch then
begin
LSource := TDispPitch(Source);
iLineSize := LSource.LineSize;
iLineColor := LSource.LineColor;
bDisplayAccent := LSource.DisplayAccent;
bVisible := LSource.Visible;
Changed;
end else
inherited;
end;
procedure TDispPitch.Changed;
begin
if FOnChange <> nil then FOnChange(Self);
end;
procedure TDispPitch.SetLineSize(Value : Integer);
begin
if iLineSize <> Value then
begin
iLineSize := Value;
Changed;
end;
end;
procedure TDispPitch.SetLineColor(Value: TColor);
begin
if iLineColor <> Value then
begin
iLineColor := Value;
Changed;
end;
end;
procedure TDispPitch.SetDisplayAccent(Value: Boolean);
begin
if bDisplayAccent <> Value then
begin
bDisplayAccent := Value;
Changed;
end;
end;
procedure TDispPitch.SetVisible(Value: Boolean);
begin
if bVisible <> Value then
begin
bVisible := Value;
Changed;
end;
end;
type
TSomeOtherClass = class(...)
private
FDispPitch: TDispPitch;
procedure DispPitchChanged(Sender: TObject);
procedure SetDispPitch(Value: TDispPitch);
public
constructor Create; override;
destructor Destroy; override;
published
property DispPitch: TDispPitch read FDispPitch write SetDispPitch;
end;
constructor TSomeOtherClass.Create;
begin
inherited;
FDispPitch := TDispPitch.Create;
end;
destructor TSomeOtherClass.Destroy;
begin
FDispPitch.Free;
inherited;
end;
procedure TSomeOtherClass.DispPitchChanged(Sender: TObject);
begin
... use new FDispPitch values as needed...
end;
procedure TSomeOtherClass.SetDispPitch(Value: TDispPitch);
begin
FDispPitch.Assign(Value);
end;