我有一个定义如下的TPersistent:
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的那种?
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; 如果是这样的话,这个过程应该如何编写?
谢谢你,恩佐
发布于 2012-12-31 15:55:08
TPersistent不支持Notification()系统。为此,您需要使用TComponent。如果在您编写的TComponent中使用了TGlyph,那么您可以让该TComponent处理通知,并在需要时更新TGlyph。否则,您将不得不将TGlyph更改为从TComponent派生,在这种情况下,如果在TComponent中使用TGlyph,则只需确保TGlyph本身调用SetSubComponent(True),以避免任何对象检查器和DFM流问题。
发布于 2012-12-31 14:40:56
这取决于如何使用您的类。Notification方法不会自动调用,只能由您自己的代码(或您的类的用户编写的代码)调用。因此,如果Notification从未被调用过,那么就没有必要调用它。
https://stackoverflow.com/questions/14097758
复制相似问题