Thursday, November 19, 2009

 

Response to comments in "Inducing the Great Divide"


I've read the -nice- article Inducing the great divide by Cobus Cruger, and was tempted to answer many comments about his approach to set object properties to visual controls.

Many comments where related to the lack of scalability of this approach, specially when a form has many model objects pointed to views not contemplated in the framework Cobus created.

I also am thinking about this problem since a long time, and started with my own framweork using the same approach of Cobus, and faced the same problems he is facing after the reader's comments.

My conclussion was that it's not possible to create a simple, generic way to fill any control with data from any object, thus, I created a framework where the programmer has to configure the objects by using "associations", where a property of an object points to a TEdit, TComboBox, TListView and so on.

For example, if the program needs to fill a listview with a TCollection of customers, in my framework, I have to configure this:


mvFramework.AddAssociation(TListViewAssociation.Create(
ListView1, // the list view associated
Customers, // Customers TCollection
['FirstName','LastName'] // Properties pointed to the First and Second column of ListView1
));


On Each TForm of the application, the programmer has to configure each control the way I explained in the previous paragraph, then the framework provides two methods, the first one to copy the data from the model and the second does the reverse.

To copy data from model to view:

mvFramework.SetDataToView;


To copy data from view back to model:

mvFramework.SetViewToData;



What if I have a component not included in the framework?

It's simple to create a custom association, like the example, that uses TListViewAssociation, one can create a TQuantumGridAssociation, for example.


Sample code:


I uploaded not so trivial example to Code Central, enjoy!.

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