Delphi 2009 ShellTreeView/ShellListView Fix

不问归期 提交于 2019-12-06 03:53:46

That's the first I've heard of this. If it's any consolation I can reproduce it here.

The first thing you should do is probably file a bug report in Quality Central, and ask on the Codegear NNTP Newsgroups.

Also, try changing TCustomShellListView.GetFolder to the code below, and see how you get on. You'll need to rebuild the package - and beware that for some reason D2009 installs a second copy of this package in Windows\System32. I renamed that with (so far) no ill effects.

function TCustomShellListView.GetFolder(Index: Integer): TShellFolder;
begin
  if Index < FFolders.Count then
    Result := TShellFolder(FFolders[Index])
  else
    Result := NIL;
end;

Nothing suggested so far works to fix the problem... but if I remove the ShellListView component from a demo project and then close the project no exception is created. I think the problem is with the ShellListView component not the ShellTreeView.

The problem may be larger than it appears.

{ TCustomShellTreeView }
...
  TCustomShellTreeView = class(TCustomTreeView, IShellCommandVerb)
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override; //$$jp shellctrl.pas 26.08.2007: missing "override"
    procedure Refresh(Node: TTreeNode);
...

destructor TCustomShellTreeView.Destroy;
begin
  //$$jp: ClearItems;
  //$$jp: raises EInvalidOperation and access-violations (shellctrl.pas 26.08.2007)
  FRootFolder.Free;
  inherited;
end;

The problem occurs only at design time.

Here' s a solution for the TShellListView component to apply on ShellCtrls.pas file:

destructor TCustomShellListView.Destroy;
begin
  ClearItems;
  if not (csDesigning in ComponentState) then // Avoid design time error
  FFolders.Free;
  FreeAndNil(FRootFolder);
  inherited;
end;

procedure TCustomShellListView.DestroyWnd;
begin
  ClearItems;

  // Avoid error in inherited DestroyWnd procedure :
  if csDesigning in ComponentState then
  Items.Count := 0;
  inherited DestroyWnd;
end;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!