hcOPF ReadOnly Object Attributes
For those of you looking at upgrading to XE2 for live bindings, or XE3 to get visual live bindings I thought I would mention that hcOPF supports object binding with earlier versions of Delphi (D7 and up). Not only that, but you’re not reliant on a black box expression engine. Bindings in hcOPF are written in Delphi and debuggable in Delphi. In fact, it’s quite easy to write your own mediators to support any non data aware control you want to use and best of all, since hcOPF is open source, you can modify it to suit your own needs, and there are no undocumented ’secrets’.
hcOPF automatically handles ReadOnly attributes ‘out of the box’, by assuming that the domain object is the source of the truth. That means if an attribute on the domain object is readonly, then the mediator informs the UI control that it should also be readonly. There are some situations though, where this is not desirable. For instance, if you want to display some boolean values on a form when a client is selected, but in order to edit the client information, the user needs to go into the client profile form, you don’t want users inadvertently changing client information by clicking on the checkboxes. In this scenario you can toggle the AutomaticReadOnly property of the mediator (assuming it’s implemented) to False. AutomaticReadOnly is normally True by default, and means that the mediator will ensure the UI control mirrors the domain object’s ReadOnly attribute, or will behave as if the attribute is ReadOnly if the object itself is marked as ReadOnly. By changing AutomaticReadOnly to False, you can control the UI control’s ReadOnly behaviour yourself. In the example given, the checkboxes would be disabled.
I recently added a new ReadOnly field variable to ThcAttribute since I ran into a scenario where I wanted to use AutomaticReadOnly but wanted to make certain object attributes ReadOnly. Since the ThcAttribute.ReadOnly property is determined by its MetaData, changing it for one attribute in one object instance effectively changed it for that attribute in all object instances. Adding the ReadOnly field variable and initializing it from the attribute definition (ThcAttributeDef) effectively solved this issue.