首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TPersistent:通知

TPersistent:通知
EN

Stack Overflow用户
提问于 2012-12-31 13:22:02
回答 2查看 188关注 0票数 0

我有一个定义如下的TPersistent:

代码语言:javascript
复制
  TGlyph = class(TPersistent)
  private
    FOwner: TControl;
    FLayout: TGlyphAlignment;
    FVisible: Boolean;
    FImageIndex: Integer;
    FImages: TImageList;
    ..............
  protected
    procedure Invalidate;
  public
    constructor Create(AOwner: TControl);
    destructor Destroy; override;
    .............
  published
    property ImageIndex: Integer read FImageIndex write SetImageIndex default -1;
    property Images: TImageList read FImages write SetImages;
    .............
  end;

是否有必要有一个通知过程,将nil值赋给FImages字段,例如您用于TComponent的那种?

代码语言:javascript
复制
procedure TGlyph.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited;
  if (Operation = opRemove) and (AComponent = FImages) then
  begin
    FImages.OnChange := nil;
    FImages := nil;
    Invalidate;
  end;
end; 

如果是这样的话,这个过程应该如何编写?

谢谢你,恩佐

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-31 15:55:08

TPersistent不支持Notification()系统。为此,您需要使用TComponent。如果在您编写的TComponent中使用了TGlyph,那么您可以让该TComponent处理通知,并在需要时更新TGlyph。否则,您将不得不将TGlyph更改为从TComponent派生,在这种情况下,如果在TComponent中使用TGlyph,则只需确保TGlyph本身调用SetSubComponent(True),以避免任何对象检查器和DFM流问题。

票数 0
EN

Stack Overflow用户

发布于 2012-12-31 14:40:56

这取决于如何使用您的类。Notification方法不会自动调用,只能由您自己的代码(或您的类的用户编写的代码)调用。因此,如果Notification从未被调用过,那么就没有必要调用它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14097758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档