我需要有关如何实现可以在对象Inspector中显示的类的帮助

XBa*_*000 0 delphi properties class object custom-component

我有

...
  TDispPitch = class
  private
    iLineSize: Integer;
    iLineColor: TColor;
    bDisplayAccent: Boolean;
    bVisible: Boolean;
  published
    property LineSize : Integer read iLineSize write iLineSize;
    ...etc
  end;
...
Run Code Online (Sandbox Code Playgroud)

我想要在Object Insepector中显示此功能来编辑设置.

我尝试添加

property DispPitch: TDispPitch read FDispPitch write FDispPitch. like 
Run Code Online (Sandbox Code Playgroud)

可以显示DispPitch,但我看不到它的属性.比如LineSize,LineColor等

vcl*_*per 6

您必须从TPersistent,或后代派生您的类,以使其在Object Inspector中可用:

TDispPitch = class(TPersistent)
private
  ...
published
  property ...
  ...
end;
Run Code Online (Sandbox Code Playgroud)

来自Delphi文档:

TPersistent是具有赋值和流功能的所有对象的祖先.

  • 您还需要覆盖`TPersistent.Assign()`方法,然后让包含类的属性使用一个setter方法,该方法调用Assign()insted直接指定其字段指针.看到我的其他答案. (2认同)