Hotfix available: CodeSnip bug fix fix
It had to happen didn't it? Not long after my post about yesterday's bug fix release of CodeSnip, Oliver reached out to point out a potential problem with the way I'd implemented it. See the linked post and comments if you're interested in the details.
Suffice to say that the problem was sufficient for me to hunt for an alternative solution. Having found one I've rushed out hotfix v4.24.2 to patch yesterday's release (v4.24.1) and make it more robust.
Whether or not you downloaded yesterday's you really should update CodeSnip to the hotfix release.
⮞ Get hotfix release v4.24.2 from GitHub.
For more info please see the similar post on the CodeSnip Blog.
The root cause of that bug is when a TreeView is recreated all Nodes save their state into a MemoryStream then they get destroyed and then recreated from that MemoryStream.
ReplyDeleteMy advice is to store the IView reference in the Data property of the TViewItemTreeNode Data := Pointer(Value); and back with Result := IView(Data);
The management for the IView references goes to TOverviewFrame which keeps the references in a TList;
TOverviewTreeBuilder will get a reference of that list and on Build it will clear the list and adds all IView references.
I made a quick test on your source and it runs totally fine even after removing all of that hacking stuff ;o)
Happy Easter
Thanks for that Oliver. I was considering trying to use the Data property instead of the custom property in the derived custom tree node class.
DeleteBut I didn't consider casting the IView reference directly to Pointer, I thought I'd need to get at the underlying object through nefarious means! I guess that Pointer(IView) must use the pointer to the implementing object?
I'll certainly try that. Many thanks. The reason I sub classed TTreeNode to add the IView property is because I don't like casting to Pointer, but it's certainly much cleaner code than the current fix!
Given that the Easter bank holiday has brought its usual vile weather here in Wales, I don't want to be out and about, so should have some time to try this!
Happy Easter to you too.
Just in case you missed it on GitHub, your patch has been rolled into release v4.25.0. Thx again.
Delete