<$BlogRSDUrl$>

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 :-






Comments:
It's work fine with expression like
FEhContact.Expression:='MyClass.allInstances', But how do you make for expression with context :

i.e :
In a model :
Customer -1-----0..n--Contact

A contact is owned by a only one Customer.
How do you make :

FEhContact.Expression:='self.Contacts';

Regards.
 
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 :-

FEhCustomer := ExpressionHandle.Create;
FEhCustomer.RootHandle := FRootHandle;
FEhCustomer.Expression := 'Customer.allInstances->select(fullName=''David Clegg'')->first';

FEhContact := ExpressionHandle.Create;
FEhContact.RootHandle := FEhCustomer;
FEhContact.Expression := 'self.Contacts';

Please forgive me if the above doesn't compile. I don't have D2006 available at present, so this is all from memory.
 
Post a Comment

This page is powered by Blogger. Isn't yours?