目前需要一个鼠标单击列头能实现排序功能的ListView控件,所以现从TListView继承生成子控件TSortListView,希望在TSortListView内部接收ColumnClick和Compare事件并实现排序。处理的代码
已经写好了(MyColumnClick和MyCompare),但不知道怎么接收对应的事件来调用我的排序处理代码。
忘高手指点一二,小弟先谢谢了。unit SortListView;interfaceuses
  Windows, Messages, SysUtils, Classes, ComCtrls, Commctrl, WinSock;type
  TSortListView = class(TListView)
  private
    IntSortCol:Integer;//当前鼠标点击排序的列
    BlDesc:Boolean;//升序、降序标记
    //当接收到ColumnClick事件时调用过程MyColumnClick进行处理
    procedure MyColumnClick(Sender: TObject; Column: TListColumn);
    //当接收到Compare事件时调用过程MyCompare进行处理
    procedure MyCompare(Sender: TObject; Item1,
  Item2: TListItem; Data: Integer; var Compare: Integer);
  protected  public  published  end;procedure Register;implementationprocedure TSortListView.MyColumnClick(Sender: TObject; Column: TListColumn);
begin
  IntSortCol := Column.Index;
  Self.AlphaSort;
  BlDesc := Not BlDesc;
end;procedure TSortListView.MyCompare(Sender: TObject; Item1,
  Item2: TListItem; Data: Integer; var Compare: Integer);
beginIf IntSortCol = 0 then
    Compare := CompareStr (Item1.Caption, Item2.Caption)
  Else
     Compare := CompareStr (Item1.SubItems [IntSortCol - 1],
  Item2.SubItems [IntSortCol - 1]);  If(BlDesc) Then
     Compare := 0-Compare;
end;
procedure Register;
begin
  RegisterComponents('Win32', [TSortListView]);
end;end.