TreeView + ListView - Exception in treeview.inc when selecting a ListItem lazarus / 31-LCL ---------------------------------------------------------------------- PeterX · 2016-03-24 16:27 Hi all, I chained a TTreeView with a TListView (on a TPanel as Parent) to be working as something like a "Windows Explorer". *****  PLEASE APOLOGISE  *****   Example Code Project soon follows !!! *****  PLEASE APOLOGISE  ***** I get an Exception in treeview.inc under the following circumstances: ( please see screenshot 1 .. ) - in ListView (NOT in TreeView !) click on folder (ListItem) "Windows" - in TreeView collapse the "Sub"TreeNodes under (TreeNode) "Windows"   by clicking the arrow left of node "Windows" - in ListView click on any of the listed subfolder (ListItems) of (TreeNode) "Windows" => Exception in Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TTreeNode.GetTreeView: TCustomTreeView;begin  if Owner <> nil then    Result := Owner.Owner  else    Result := nil;end;  (var)  Owner =     (please see screenshot 2) Instead, when I first EXPAND the collapsed TreeNode "Windows" again, with Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Self.fTreeView.Selected.Expand( FALSE);the Exception does not occur. *****  PLEASE APOLOGISE  *****   Example Code Project soon follows !!! *****  PLEASE APOLOGISE  ***** This weekend I will set up a simple example project that shows up the behaviore and does not include all the overhead of my project code. Please apologise & stay tuned .. ---------------------------------------------------------------------- JD · 2016-03-24 22:29 Have you seen this component http://www.benibela.de/components_en.html#treelistview that combines a TTreeView & TListView? It may be worth your while to try it. JD ---------------------------------------------------------------------- PeterX · 2016-03-24 23:06 Yes, I've seen that before, thank You for the hint. But it does not look like the Windows Explorer as far as I can see. ---------------------------------------------------------------------- balazsszekely · 2016-03-25 04:33 Quote@PeterX Instead, when I first EXPAND the collapsed TreeNode "Windows" again, with Self.fTreeView.Selected.Expand( FALSE); Make sure that "selected" is not nil: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if Self.fTreeView.Selected <> nil then  Self.fTreeView.Selected.Expand( FALSE) PS: If you doing this for learning purposes, it's a good project. If not there is a TShellTreeView/TShellListView component under the Misc tab. ---------------------------------------------------------------------- PeterX · 2016-03-25 11:25 Quote from: GetMem on March 25, 2016, 05:33:04 amMake sure that "selected" is not nil I already checked this: - "Selected" is not = NIL - also the (collapsed) subnodes of "Selected" are not = NIL ---------------------------------------------------------------------- PeterX · 2016-03-25 11:48 Quote from: GetMem on March 25, 2016, 05:33:04 amIf you doing this for learning purposes, it's a good project. If not there is a TShellTreeView/TShellListView component under the Misc tab. I am not doing this for learning purposes but for some of my projects that need a component for file navigation and selection. LCL's TShellTreeView / TShellListView components are not really perfect and they also would need a hack of the original LCL sources to make a stable integration of making Windows' ICONs visible.  There are some issues :   TShellTreeView / TShellListView can't access the "Windows SystemIcon" ImageList,   here someone tried a workaround, with hacking LCL's sources: http://forum.lazarus.freepascal.org/index.php/topic,31537.msg202732.ht ml#msg202732   I capture the icon images this way: http://forum.lazarus.freepascal.org/index.php/topic,32014.msg205906.ht ml#msg205906   Old DELPHI did it this way (but it does not work under FPC, LCL doesn't accept the Handle) : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //* CreateImages for Delphi :procedure TExplorerTreeView.CreateImages;var  hImagesList : Uint;  SFInfo      : TSHFileInfo;begin  hImagesList:= SHGetFileInfo( '', 0, SFInfo, SizeOf( SFInfo),                             SHGFI_SYSICONINDEX or SHGFI_SMALLICON);  if hImagesList <> 0 then    begin      SmallImagesList.Handle:= hImagesList;      SmallImagesList.ShareImages := True;    end;  Self.Images:= SmallImagesList;end;  //CreateImages for Delphi    TListItems and TListItem can't be used standalone, they are badly chained with TListView, http://forum.lazarus.freepascal.org/index.php/topic,31537.msg202619.ht ml#msg202619 and TListView seems to only show Files, but no folders (?)   => please see appended Screenshot, on the right there is TShellTreeView / TShellListView So this here ... : http://lazplanet.blogspot.de/2013/06/create-simple-file-browser- in-2-minutes.html   is not the full truth ... :-( Cheers, Peter ---------------------------------------------------------------------- Bart · 2016-03-25 12:11 I (partly) agree with your observations about TShellTreeView. We really need a better implementation that uses native OS style of presenting the information and interfacing with the OS. While there are some (free) examples for Windows, I haven't come across one for Linux/OSX. Bart ---------------------------------------------------------------------- PeterX · 2016-03-25 12:34 Quote from: Bart on March 25, 2016, 01:11:52 pmI (partly) agree with your observations about TShellTreeView. We really need a better implementation that uses native OS style of presenting the information and interfacing with the OS. While there are some (free) examples for Windows, I haven't come across one for Linux/OSX. Bart I don't like to disclose my buggy code right now. But I planned to disclose the base Component as soon as I get no crashes anymore. Probably this can give some hints for a reworked TShellTreeView/TShellListView. ---------------------------------------------------------------------- JuhaManninen · 2016-03-25 12:43 Quote from: PeterX on March 25, 2016, 01:34:57 pmProbably this can give some hints for a reworked TShellTreeView/TShellListView. How about improving those components instead of creating new ones. They can be changed a lot and extended as long as they remain backwards compatible (more or less). The widgetset dependent code must be encapsulated correctly, the component's main code must not contain Windows specific stuff. Initially only Windows would provide icons etc., for other widgetsets it can implemented later. ---------------------------------------------------------------------- PeterX · 2016-03-25 13:01 Quote from: JuhaManninen on March 25, 2016, 01:43:47 pmHow about improving those components instead of creating new ones. Things can be solved in many ways. I looked into ShellCtrls.pas  and from my point of view some code is very complex to read. Even though it works, it is difficult to read into it and to maintain the code years later .. ---------------------------------------------------------------------- Bart · 2016-03-25 13:38 Quote from: JuhaManninen on March 25, 2016, 01:43:47 pmHow about improving those components instead of creating new ones. They can be changed a lot and extended as long as they remain backwards compatible (more or less). The widgetset dependent code must be encapsulated correctly, the component's main code must not contain Windows specific stuff. It would probably mean that almost all of the implementation would have to go to the WS. I've seen some code for Windows and I think it'll be hard to abstract all of that into datatypes/interfaces that can be accessed in a cross- platform way. Bart ---------------------------------------------------------------------- PeterX · 2016-03-26 11:50 Hi, I've set up the proposed Example Project. Unfortunately my example does not end up in an exception as my component does. I will have to digg deeper .. ---------------------------------------------------------------------- PeterX · 2016-03-26 17:48 Quote from: GetMem on March 25, 2016, 05:33:04 amMake sure that "selected" is not nil: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if Self.fTreeView.Selected <> nil then  Self.fTreeView.Selected.Expand( FALSE) Hello GetMem, You where right !  Inside my TListView code the "Selected" was valid. But then furtheron in my TTreeView the "Selected" changed / updated to = NIL which caused my Exception (when I collapse more than one Parent Node ..). I have to manually expand all Nodes that I collapsed before, with my MouseClick, to get back a fully restored / expanded Tree,  along the full path of my selected SubDirectory ! ---------------------------------------------------------------------- PeterX · 2016-03-27 20:24 Quote from: Bart on March 25, 2016, 01:11:52 pmI (partly) agree with your observations about TShellTreeView. We really need a better implementation .. Things are easy when - as in LCL's  TShellListView - only files are shown. Things get more complex when You additionally see folders. When clicking on folders in the TShellListView You have to also update the TShellTreeView. I currently work on finding a way that allows collapsing the Tree and not losing the selected folder in the TShellListView  .. and not corrupting  TTreeView.DoSelectionChanged() or TTreeView.TreeView1Expanding()