views:

1361

answers:

5

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?

+3  A: 

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;
Roddy
I strongly agree - this should be posted in QC, then others can up-vote it there.
Argalatyr
A: 

I saw a post in the codegear groups about this that referred to a bug report but I can not find it. I was hoping someone had found a "Quick Fix" because the AV's are annoying.

This looks more like a comment than an answer to your question, doesn't it?
Argalatyr
May be he hadn't enough points to comment, when he wrote this answer...
Uwe Raabe
Good point. I did not down-vote in the first place, and your point makes me gladder that I did not.
Argalatyr
A: 
{ 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;
A: 

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.

A: 

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