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 :-
(2) comments
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 Borland.Eco.Handles to the uses clause (interface section)
- Add these private fields in the form:
- Add this in the OnCreate event handler of the form:
- 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):
private
{ Private declarations }
FEcoSpace:TEcoSpace;
FEhContact:ExpressionHandle;
FRefHandle:ReferenceHandle;
procedure TMainForm.FormCreate(Sender: TObject);
begin
FEcoSpace:=TEcoSpace.Create;
FEcoSpace.Active:=True;
FRefHandle:=ReferenceHandle.Create;
FRefHandle.EcoSpace:=FEcoSpace;
FEhContact:=ExpressionHandle.Create;
FEhContact.RootHandle:=FRefHandle;
FEhContact.Expression:='Contact.allInstances';
ListConnector1.DataObject:=FEhContact.GetList;
ListConnector1.Active:=True;
end;
procedure TMainForm.ListConnector1NewRecord(DataSet: TDataSet);
begin
Contact.Create(FEcoSpace);
FEhContact.EnsureBindingList;
ListConnector1.CheckBrowseMode;
ListConnector1.Edit;
end;