如何向组件添加反映对象检查器的属性

发布于 2024-10-16 14:04:26 字数 43 浏览 0 评论 0原文

在Delphi 7中,当向对象添加属性时,如何在对象检查器中看到该属性?

in Delphi 7 , when adding a propery to an object, how is it possible to see that property in the object inspector?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

烟雨凡馨 2024-10-23 14:04:26

使该属性发布。例如,

private
  FMyProperty: integer;
published
  property MyProperty: integer read FMyProperty write FMyProperty;

通常,当属性更改时,您需要重新绘制控件(或进行一些其他处理)。然后你可以做

private
  FMyProperty: integer;
  procedure SetMyProperty(MyProperty: integer);
published
  property MyProperty: integer read FMyProperty write SetMyProperty;

...

procedure TMyControl.SetMyProperty(MyProperty: integer);
begin
  if FMyProperty <> MyProperty then
  begin
    FMyProperty := MyProperty;
    Invalidate; // for example
  end;
end;

Make the property published. For instance,

private
  FMyProperty: integer;
published
  property MyProperty: integer read FMyProperty write FMyProperty;

Often, you need to repaint the control (or do some other processing) when a property is changed. Then you can do

private
  FMyProperty: integer;
  procedure SetMyProperty(MyProperty: integer);
published
  property MyProperty: integer read FMyProperty write SetMyProperty;

...

procedure TMyControl.SetMyProperty(MyProperty: integer);
begin
  if FMyProperty <> MyProperty then
  begin
    FMyProperty := MyProperty;
    Invalidate; // for example
  end;
end;
邮友 2024-10-23 14:04:26

将该属性添加到已发布部分,它将使其显示在对象检查器上,如下所示:

TMyComponent = class(TComponent)
 ...
published
  property MyProperty: string read FMyProperty write SetMyProperty;

Add that property to the published section, it will make it appear on the Object Inspector, like this:

TMyComponent = class(TComponent)
 ...
published
  property MyProperty: string read FMyProperty write SetMyProperty;
永不分离 2024-10-23 14:04:26

来自文档

已发布的属性中声明的属性
组件类的部分
声明在对象中是可编辑的
设计时检查员。

From the docs:

Properties declared in a published
section of the component's class
declaration are editable in the Object
Inspector at design time.

王权女流氓 2024-10-23 14:04:26

不要忘记该组件需要在 Delphi 中注册(最好在设计时包中),否则您将在对象检查器中根本看不到任何内容!

我的意思是...我可以创建一个名为 TMyPanel 的新 TPanel 后代,并向其添加一个新的 Published 属性:

type
  TPanel1 = class(TPanel)
  private
    FMyName: String;
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
  published
    { Published declarations }
    property MyName : String read FMyName write FMyName;
  end;

但是如果您没有使用 RegisterComponent 注册新类,则该属性不会显示在对象检查器中:

procedure Register;
begin
  RegisterComponents('Samples', [TPanel1]);
end;

只是为了完全的 :-)

Don't forget that the Component needs to get registered within Delphi (preferable in a Design Time Package) or you you won't see anything in the Object Inspector at all !!!

I mean ... I can create a new TPanel descendant called TMyPanel and add a new Published property to it :

type
  TPanel1 = class(TPanel)
  private
    FMyName: String;
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
  published
    { Published declarations }
    property MyName : String read FMyName write FMyName;
  end;

but that property won't get displayed in the Object Inspector if you havn't registered the new class using RegisterComponent :

procedure Register;
begin
  RegisterComponents('Samples', [TPanel1]);
end;

Just to be complete :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文