Idle Musings of a Delphi Junkie

Welcome to the Blog of David Clegg. I am a hard-core Delphi fan, so most of my posts will probably reflect this.

Thursday, August 11, 2005

Now why didn't I think of that?

I've recently had an article posted on BDN explaining how to use VCL.NET with ECO. While I was relatively happy with it, the approach does lose any databinding support that using ECO with WinForms provides

In the ECO newsgroups today, Kostas Terzides outlined how to use a TListConnector class to enable databinding standard VCL.NET databound controls to an ExpressionHandle. I've outlined his steps below :-

Drop a TListConnector (from Borland.Vcl.ADONETDb namespace- it might not be installed by default) in the form and add a TDataSource and a TDBgrid (or your favorite 3rd party grid). Wire them all up.

Add this in the event handler for OnNewRecord of ListConnector1 (this is a little bit weird (the dataset gets automatically from dsInsert to dsEdit), but it is a quick and dirty solution. If someone has a better one please post):

ExpressionHandles need to be rooted in some context, which is what the RootHandle property does. Therefore, you could simply root the ExpressionHandle so it's context is the Customer you're interested in.

An easy way to achieve what you want is to use the ReferenceHandle.SetElement method to root it's context :-

FRootHandle.SetElement(FCustomer.AsIObject);

You would then be able to use the OCL expression 'self.Contacts' to return all Contacts for the desired customer.

ExpressionHandles can have their contexts rooted in the result evaluated by another ExpressionHandle. So alternatively you could create another ExpressionHandle, and set it's Expression property accordingly, e.g :-