掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
カスタムコントロール:独自イベントを作成するには? (ID:21593)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
{ >MyPersistentプロパティが変更したときに >procedure SetMyPersistent(const Value:TMyPersistent); クラス指定子が無いのですが、これもクラスメソッドですよね? イベントのアサイン先が逆っぽいなぁ。 TMyPersistentのプロパティの変化に応答したいのであれば、 TMyPersistent.OnChangeに TMyCustomControlのメソッドをアサインするのが 一般的なのではないかと思います。 直してみました } interface TMyPersistent=class(TPersistent) private FOnChanging: TnotifyEvent; FMyTag: Integer; published Property MyTag:Integer Read FMyTag write setMyTag ; property OnChanging:TnotifyEvent read FOnChanging write FOnChanging ; end; TMyCustomControl = class(Tcustomcontrol) private //FOnMyPersistentChange: TNotifyEvent; //削除 FMyPersistent:TMyPersistent; procedure SetMyPersistent(const Value:TMyPersistent); protected procedure MyPersistentChange(AObject:TObject); published property OnMyPersistentChange:TNotifyEvent Read FOnMyPersistentChange write FOnMyPersistentChange ; property MyPersistent:TMyPersistent read FMyPersistent write SetMyPersistent ; end; implementation {TMyPersistent} procedure TMyPersistent.SetMyTag(const Value: Integer); begin if FMyTag<>Value then begin FMyTag := Value; if Assigned(FOnChanging) then FOnChanging(Self); end; end; {TMyCustomControl} constructor TMyCustomControl.Create(AOwner: TComponent); begin //FOnMyPersistentChange:=MyPersistent.FOnChanging; // ? FMyPersistent:= TMyPersistent.Create; //追加 FMyPersistent.OnChanging:= MyPersistentChange; //追加 end; procedure TMyCustomControl.MyPersistentChange(AObject: TObject); begin //inherited ; //? //AObjectってなんだろう if assigned(FOnBlockChange) then FOnBlockChange(Self); Repaint; end; procedure TMyCustomControl.SetMyPersistent(const Value:TMyPersistent); begin if not Assigned( Value) then Raise Exception.Create('MyPersistent is nil'); if MyPersistent<>Value then begin MyPersistent.Assign(Value); end; //または { if MyPersistent<>Value then begin MyPersistent.Free; MyPersistent:= Value; end; } end;
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.