Inheriting Problems

Recently I was working on a project in which I dropped a ThcUIObjectBinder component from the hcOPF framework onto a TFrame.  I put the frame onto a TForm container and kept getting a dialog in Delphi complaining that a ‘ThcUIBindingItem cannot be assigned to a ThcUIBindingItem’.  The error message doesn’t make much sense, but I had seen similar dialogs in the past, so I figured it came from the Assign() method.  I had not implemented an override in my ThcUIBindingItem class so it was using the default in TPersistent which generates the error dialog I had witnessed.

I checked out the DFM file for my form instance, and found that the bindings were empty, yet in the frame, I had two binding items.  This was also consistent with my supposition that it had to do with the Assign method.  When a component on a DFM effectively inherits it’s properties from a component in another DFM, it makes sense that the component is Assigned the properties of the “ancestor”  and then these properties are over written or augmented by the property values in the “descendant” DFM.  Of course the problem is that Assign() is virtual so you have no idea that the method must be overridden in some circumstances to get the behaviour you would expect because it isn’t documented in the help.

Sure enough, I added my own Assign() override and all is well.

Leave a Reply