Delphi 2009 ShellTreeView/ShellListView Fix

拥有回忆 提交于 2019-12-12 09:46:48

问题


When a Delphi 2009 project is closed with ShellTreeView/ShellListView on the mainform in the IDE Index out of bounds(0) exceptions are generated. Is there a fix for ShellTreeView/ShellListView so the exceptions can be eliminated?


回答1:


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;



回答2:


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.




回答3:


{ 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;



回答4:


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;


来源:https://stackoverflow.com/questions/403411/delphi-2009-shelltreeview-shelllistview-fix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!