1

I have a TListView descendant which introduces additional features like sorting and loading from a dataset.

I now wish to modify the class so that whenever an item is checked or unchecked it is added or removed in an internal list of checked items so that an application using an instance of the component can easily read the number and location of checked items without having to iterate over all the items in the list view.

Unfortunately, rather than abstracting handling of the check/uncheck operation into some internal method (like DoCheck) that I could override, TCustomListView seems to embed the check logic deep in a large message-handling function.

The only way I can think of to introduce my own behavior neatly into the component is to hijack the OnItemChecked property, causing that property to read and write FOnItemCheckedUser (for example) rather than FOnItemChecked, put my own code in FOnItemChecked, and call FOnItemCheckedUser from my code.

Is there a more straightforward way to handle this? If not, is my idea feasible and safe to implement?

4

1 に答える 1

4

チェックイベントコードがメッセージハンドラーに埋め込まれているのは残念ですが、それは目を見張るものではありません。同じメッセージを自分でキャッチして処理します。親クラスのメッセージハンドラーがチェックするのと同じ条件を検出し、そこでカスタムアクションを実行します。その後、を呼び出しますinherited

type
  TListViewDescendant = class(TListView)
  private
    procedure CNNotify(var Message: TMessage); message cn_Notify;
  end;

procedure TListViewDescendant.CNNotify(var Msg: TMessage);
begin
  if IsCheckBoxNotification(Msg) then
    DoSpecialCheckBoxHandling;
  inherited;
end;
于 2010-02-09T03:52:42.140 に答える