我改了TTreeView的Item.Data的属性为String,并重新生成了一个组件,其它的都没有问题,但就是在 OnGetImageIndex和OnGetSelectedIndex时事件时会出错。下在是我自己跟据ComCtrls的代码改的
……
TuTVExpandedEvent = procedure(Sender: TObject; Node: TuTreeNode) of object;
……
FOnGetSelectedIndex: TuTVExpandedEvent;
property OnGetImageIndex: TuTVExpandedEvent read FOnGetImageIndex write FOnGetImageIndex;
property OnGetSelectedIndex: TuTVExpandedEvent read FOnGetSelectedIndex write FOnGetSelectedIndex;
……
procedure TUserTreeView.GetSelectedIndex(Node: TuTreeNode);
begin
  if Assigned(FOnGetSelectedIndex) then FOnGetSelectedIndex(Self, Node);
end;
……这里是原代码:
……
TTVExpandedEvent = procedure(Sender: TObject; Node: TTreeNode) of object;
……
FOnGetSelectedIndex: TTVExpandedEvent;
property OnGetImageIndex: TTVExpandedEvent read FOnGetImageIndex write FOnGetImageIndex;
property OnGetSelectedIndex: TTVExpandedEvent read FOnGetSelectedIndex write FOnGetSelectedIndex;
……
procedure TCustomTreeView.GetSelectedIndex(Node: TTreeNode);
begin
  if Assigned(FOnGetSelectedIndex) then FOnGetSelectedIndex(Self, Node);
end;
……为何我的代码运行就会出错,但Delphi自带的却可以运行?

解决方案 »

  1.   

    错误内容:
     Project CHM.exe reised exception class EAccessViolation with message 'Access violation at address 00404576 in module 'CHM.exe'. Read of address 00000100'.Process Stopped.Use Step or Run to contioue.
      

  2.   

    我自己做的TTreeView组件,在安装时编译通过,安装成功,但运行时就不能用,这是为什么?还有,同样的代码,我在办公室(Win2000)里可以用,但在家里(WinXp)却不能用,差别有这么大吗?
      tagTVSORTCB = packed record
        hParent: HTreeItem;
        lpfnCompare: TTVCompare;
        lParam: LPARAM;
     ……
    var
      SortProc: TTVCompare ;
    begin
    ……
        with SortCB do
        begin
          if not Assigned(SortProc) then lpfnCompare := @DefaultTreeViewSort
          else lpfnCompare := SortProc;//XP 下这里出错,
    //错误码信息:Incompatible types: 'PFNTVCOMPARE' and 'Pointer';      hParent := ItemId;
          lParam := Data;
        end;
    ……