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

最佳答案

使属性 published 。例如,

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;

10-08 00:18