Recent

Author Topic: [SOLVED] How to get the TListItem on TShellListView's "AddItem" event?  (Read 909 times)

ToolGIS

  • New Member
  • *
  • Posts: 18
Code: Pascal  [Select][+][-]
  1. procedure TFormMain.ShellListViewResourcesAddItem(Sender: TObject;
  2.         const ABasePath: String; const AFileInfo: TSearchRec; var CanAdd: Boolean);
  3. begin
  4.   if Sender is TShellListView then
  5.     // Each event reported correctly per item added..
  6.     WriteLn('ABasePath ' + ABasePath);
  7.     // But how do I get the TListItem that's being added?
  8. end;

The only way I found is to get TShellListView(Sender).Items and iterate over them, but this is inefficient because it loops a growing number of items as they are being added. Even so, as I discovered, the Items at this point are only those previously added. So this still does not give me the Item being added.

Surely a TListItem should have been part of this argument list (as it is with "OnChange").
« Last Edit: April 27, 2023, 09:00:00 pm by ToolGIS »

Bart

  • Hero Member
  • *****
  • Posts: 5743
    • Bart en Mariska's Webstek
Re: How to get the TListItem on TShellListView's "AddItem" event?
« Reply #1 on: April 26, 2023, 03:21:13 pm »
This event gives you the opportunity to inspect the properties of what is about to be added, and to reject it by setting CanAdd to False.
Only after this event has been fired (if assigned) and CanAdd is True, the Item itself is created.

It's by design.

If you dont need the CanAdd feature, you'l probably be better of with the OnFileAdded event.

Bart
« Last Edit: April 26, 2023, 03:23:29 pm by Bart »

ToolGIS

  • New Member
  • *
  • Posts: 18
Re: How to get the TListItem on TShellListView's "AddItem" event?
« Reply #2 on: April 26, 2023, 04:46:32 pm »
This event gives you the opportunity to inspect the properties of what is about to be added, and to reject it by setting CanAdd to False.
Only after this event has been fired (if assigned) and CanAdd is True, the Item itself is created.

It's by design.

If you dont need the CanAdd feature, you'l probably be better of with the OnFileAdded event.

Bart

Thanks, this seems to be the one.  :D

 

TinyPortal © 2005-2018