{"id":2610,"date":"2012-10-28T06:52:04","date_gmt":"2012-10-28T10:52:04","guid":{"rendered":"http:\/\/www.hoogervorst.ca\/arthur\/?p=2610"},"modified":"2012-10-28T06:52:04","modified_gmt":"2012-10-28T10:52:04","slug":"treeview-and-storage","status":"publish","type":"post","link":"http:\/\/www.hoogervorst.ca\/arthur\/?p=2610","title":{"rendered":"Treeview and storage"},"content":{"rendered":"<p><span class=\"dropcap\">I<\/span>&#8216;ve not written a while about programming, let alone anything about that mailing program, <a href=\"http:\/\/www.hoogervorst.ca\/arthur\/?cat=27\">RoundAbout<\/a>. Today&#8217;s subject is the Windows TreeView control and its data section, the TreeNodes. As you probably know, a TreeView shows data in an hierarchical way, allowing users to &#8216;expand&#8217; or &#8216;close&#8217; so-called TreeNodes, so to expose or hide data they do and don&#8217;t want to see. TreeNodes in the Windows world can have user-data attached to it and often, developers will use this to store program specific information. I believe in .Net, this data propery is called &#8216;Tag&#8217;: in the Delphi world, it was called plainly &#8216;Data&#8217;. So code-wise this could look like this:\n<\/p>\n<p><code><br \/>\n  var Node: TTreeNode;<br \/>\n  \/* FolderData is a pointer to a record *\/<br \/>\n  Node := TreeView.Items.AddChild(Node, FolderData^.Name);<br \/>\n  \/* Attach the FolderData to the current node *\/<br \/>\n  Node.Data := FolderData;<br \/>\n<\/code>\n<\/p>\n<p>Early in the process of development, it was noticed that any font or even layout changes caused severe crashes in the TreeView: The TreeView in RoundAbout holds account and message\/mail folder information via each TreeNode&#8217;s Data member. After a long investigation, I noticed that this was caused by the Delphi TreeView control itself: whenever a window anywhere was refreshed, Windows would send a message to the TreeView control to refresh and <em>recreate<\/em> itself. Let me say that again: whenever a font was changed in RoundAbout, this would trigger any TreeView to recreate itself. I think this issue was resolved in later versions of Delphi, but I decided to create my own control (PMTreeView, <a href=\"http:\/\/roundabout.cvs.sourceforge.net\/viewvc\/roundabout\/components\/PMTreeview.pas?view=markup\">code here<\/a>) to preserve the data with the following premises:\n<\/p>\n<ol>\n<li>Override CreateWnd and DestroyWnd<\/li>\n<li>Upon destruction of the treeview window, save the data for the nodes to a memorystream.\n<li>Upon creation of the treeview window, (if available) load the node data from the memorystream.\n<li>Trigger an event to notify the developer that the Data structure has changed for further activities.\n<\/ol>\n<\/p>\n<p>As I mentioned earlier, I believe in subsequent Delphi versions, Borland fixed this in their own TreeView controls. However, for a piece of code that I debugged and coded in a night or so, my own PMTreeView control wasn&#8217;t too bad of an implementation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8216;ve not written a while about programming, let alone anything about that mailing program, RoundAbout. Today&#8217;s subject is the Windows TreeView control and its data section, the TreeNodes. As you probably know, a TreeView shows data in an hierarchical way, &hellip; <a href=\"http:\/\/www.hoogervorst.ca\/arthur\/?p=2610\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,27],"tags":[146,579],"_links":{"self":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/posts\/2610"}],"collection":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2610"}],"version-history":[{"count":0,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/posts\/2610\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2610"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}