Blog
All Blog Posts | Next Post | Previous PostVisual Data Binding using TAureliusDataset
Friday, March 22, 2013
When dealing with Aurelius and any ORM framework, one common task is to build a graphical user interface to edit/display the data. Delphi users are used to the TDataset component, which not only retrieves data from the database but also act as middle layer between the data and visual controls. When using Aurelius, you don't use any TDataset descendant to directly retrieve data - all business data are objects that are retrieved by Aurelius itself.To bind your objects to visual controls, you could use the new Visual Live Bindings feature. But Aurelius also provides an additional way of doing that - you can use TAureliusDataset, a TDataset descendant which behaves as any other TDataset - the only difference is that entity objects are the "data" for this dataset.
Consider the following code:
var Customers: TList<TCustomer>; Dataset: TAureliusDataset; {...} Customers := Manager.Find<TCustomer>.List; Dataset.SetSourceList(Customers); Dataset.Open;
TAureliusDataset automatically maps each property to a field in dataset. So if your customer is declared like this:
type TCustomer = class {...} property CustName: string read FCustName write FCustName;
CurrentName := Dataset.FieldByName('CustName').AsString; Dataset.Edit; Dataset.FieldByName('CustName').AsString := CurrentName + ' - sufix'; Dataset.Post;
SpecificCustomer := Manager.Find<TCustomer>(CustomerId); Dataset.SetSourceObject(SpecificCustomer); Dataset.Open;
1. You can use existing data-aware controls. Delphi is now 18 year-old. There are numerous existing controls that support TDataset, but not live bindings. Data-aware grids, planners, controls, etc.. All of those can be used and be bound to the objects.
2. TDataset provides a temporary cache/buffer. This means that until you effectively Post, objects are not changed. Remember this acts as a TDataset. While the dataset is being edited and field contents are updated, only the internal dataset buffer is updated. Data is effectively saved in the objects (the "data") only after Post. This gives you great flexibility when you need to build user interfaces where user can cancel changes, or only update data when clicking "Ok". If you use live bindings, you would have to do something else to achieve such behavior.
Not only that, TAureliusDataset is not just a property->field mapper. It's really powerful. Here is a list of many things TAureliusDataset can do and features it supports (I might write about these in a future post):
- Fetch-on-demand (will talk about this in a future post)
- Offline, paged fetch-on-demand (same as above)
- Sub-properties (properties of associated entities)
- Entity fields (fields representing an association)
- Dataset fields (master-detail)
- Supports inheritance/polymorphism (list of objects of different classes)
- Enumerated types
- Lookup fields
- Locate/Lookup methods
- Filtered data
- Calculated fields
- Design-time support
Wagner Landgraf
This blog post has received 2 comments.
2. Tuesday, January 26, 2016 at 11:55:02 AM
Olá Anderson, nos envie um e-mail diretamente (pela aba suporte) informando exatamente o que está fazendo. É sempre bom também registrar as classes com RegisterEntity(TNomeDaClasse);
Wagner Landgraf
All Blog Posts | Next Post | Previous Post
Somos de uma empresa de tecnologia e estamos querendo adquirir o Aurelius estamos fazendo teste e não estamos conseguindo publicar no Load Field as classes criadas. Pode ser que estamos deixando de fazer algo se puder nos mandar um exemplo como feito acima para vermos o que tem de errado.
Obrigado pela atenção
Anderson
Anderson Gonçalves