DataBinding

Hi Wagner,


Sorry so many questions, I am trying to learn fast as I can and solve many issues I can by my own, but there are some things I dont find clearly in the documentation.

giving the following code:


  [Entity]
  [Table('ITEM')]
  [Inheritance(TInheritanceStrategy.JoinedTables)]
  [Id('ID', TIdGenerator.Guid)]
  TEntityItem = class(TNaharEntity)
  private
    FId: TGuid;
    FCodigo: string;
    FNome: string;
    FDescricao: Nullable<string>;
    FReferencia: Nullable<string>;


    function  GetNome: string;
    procedure SetNome(const Value: string);
    function  GetCodigo: string;
    procedure SetCodigo(const Value: string);
    procedure SetDescricao(const Value: Nullable<string>);
    procedure SetReferencia(const Value: Nullable<string>);
    function  GetDominio: Integer;
    procedure SetDominio(const Value: Integer);


  public
    [Column('ID', [TColumnProp.Unique, TColumnProp.Required, TColumnProp.NoUpdate])]
    property Id: TGuid read FId write FId;


    [Column('DOMINIO', [TColumnProp.Required], 0)]
    property Dominio: Integer read GetDominio write SetDominio;


    [Column('CODIGO', [TColumnProp.Required], 30)]
    property Codigo: string read GetCodigo write SetCodigo;


    [Column('NOME', [TColumnProp.Required], 100)]
    property Nome: string read GetNome write SetNome;


    [Column('DESCRICAO', [], 100)]
    property Descricao: Nullable<string> read FDescricao write SetDescricao;


    [Column('REFERENCIA', [], 100)]
    property Referencia: Nullable<string> read FReferencia write SetReferencia;


  end;


  [Entity]
  [Table('ITEM_PRODUTO')]
  [PrimaryJoinColumn('ID')]
  TEntityItemProduto = class(TEntityItem)
  private
    [ManyValuedAssociation([], CascadeTypeAll)]
    [ForeignJoinColumn('ID', [TColumnProp.Required])]
    FFornecedores: Proxy<TList<TEntityContato>>;


    [Association([TAssociationProp.Lazy], [])]
    [JoinColumn('ID', [])]
    FUnidade: Proxy<TEntityUnidade>;


  private
    function  GetFornecedores: TList<TEntityContato>;


    procedure SetUnidade(const Value: TEntityUnidade);
    function  GetUnidade: TEntityUnidade;


  public
    constructor Create; virtual;
    destructor  Destroy; override;


    property  Unidade: TEntityUnidade read GetUnidade write SetUnidade;


    property  Fornecedores:TList<TEntityContato> read GetFornecedores;
  end;


I will be using the the inherited table "ITEM_PRODUTO" to enter products in my Form.

However I have the "Unidade" and "Fornecedores" that are linked.

I dont know how to map that on my UI using Databinding on FMX.

I have created a package with the units that implements the entities, so I can easily load the definition on the TAureliusDataset. Super easy!! good idea!

The thing is that I need to wire my View with no code if possible !!!! I need a dumb form, with only databinding. I will need to create a view for each platform, one for web, one for mobile and one for desktop, then I need it with minimal code on the View.

The demos that comes with Aurelius are not good on this sense. It uses too much code on the View.

I could successfully connect my ITEM_PRODUTO direct fields, but I have NO IDEA how to connect the linked (Association) cases. 

I have for example the "UNIDADE" that is a table. It has ID and NOME, I would like to select the proper UNIDADE for this ITEM_PRODUTO. In a "Normal" DB I would use a lookup combo box to select the UNIDADE and set the relationship with the ITEM_PRODUTO.

I have the FORNECEDOR (supplier) that I can have more than one for each ITEM_PRODUTO, IN this case I wanted to have a combo where I can select the FORNECEDOR and add to a Grid (TStringGrid) so each added FORNECEDOR to this grid will be associated to the ITEM_PRODUTO.

IN a regular database I would add more DataSet to the view to map other needs. 

Could you give me an example for the UNIDADE what should I do to visually map using the databinding editor?

(I have no idea how to attach image files to share, on my chrome nothing worked on this forum for this)

The use of Unidade property with datasets is explained here: http://www.tmssoftware.com/business/aurelius/doc/web/index.html?entity_fields_associations.htm

The field Unidade in dataset is the object itself (not the id). Every dataset in Aurelius also has a "Self" field which is an object field pointing to the underlying object of the record. This helps you in build lookup combo boxes. So in a lookup combo box, the "KeyField" will be "Self", and the DataField will be "Unidade".

For the Fornecedor table, you can check info here: http://www.tmssoftware.com/business/aurelius/doc/web/index.html?dataset_fields_many-valued_ass.htm.

The Fornecedores field is a dataset field which holds all the list of Fornecedor objects. You can link that dataset to a detail grid. 

This is the databinding of this view:http://snag.gy/1vfGg.jpg


This is the form: http://snag.gy/3jo2f.jpg

Both cases you presented are based on source code implementation, I need to write that using the dataset and fieldbyname property.


I am trying to use the new LiveBindings (I mentioned databinding, I said it wrong)

I could manage to work on the simple field, with grid and navigator, with NO CODE AT ALL.

But have you ever tried that with the case of UNIDADE table?

I need to map the field SIGLA (KG, UN, etc) that is part of UNIDADE. This SIGLA is the lookup list data.

Not sure that is possible or how.

Why source code? Everything is at design-time. You can also put your dataset and "controller" logic in a datamodule and then just link the different forms to the dataset and fields in data module.


Honestly I don't know much about livebindings, I prefer using the dataset. Also, one of main "features" of Aurelius is that the classes are plain Delphi classes. And Aurelius associations and just simple objects or list of objects. It should be a regular use for livebindings, isn't it?

It seems that livebindings are not so simple... nothing like the DB components of VCL


look this example: http://stackoverflow.com/questions/10211668/tdblookupcombobox-firemonkey

there are a lot more that can be done with livebindings, but there are some simple things are just madness.

In  your demo app for FMX you do everything manually. There is no DB components. Besides that is an option, in a MVP/MVC style programming you are adding a lot of code on the view.

I will try to create helper methods on my model/presenter layer to fill in the comboboxes, I dont see other way right now.

Thank you!

Yes, I felt that the few times I used live bindings. Personally I don't like them, and avoid use it in my real projects. Even in C#, when I used bindings, although it's usually great, there are some things that I didn't like.

I personally like the TDataset approach very much. People don't give TDataset much credit because they associate it with the "old" way of doing Delphi database applications. But with TAureliusDataset, it has nothing to do with database, it's just a binding mechanism between controls and objects. The TDataset is actually a very complex and working system for data binding. It has data (field names), display label, display width, default expressions, required flag, readonly flag, a lot of things that make it a good "framework" for data binding. It's just there to be used. 
And from what I understand, you can still use livebindings with it (TDataset).
1 Like

My last shot on this thread :)


I think you should provide an example using livebindings with aurelius. Like rewriting that Music demo on FMX for livebindings.

The fact is that I am now like 4 hours navigating on many forums and threads and a lot of people are lost about using livebindings. I believe you will be limiting the use of Aurelius without a real example for FMX at least. For VCL will be fine.

Just my 2 cents, you could rely the idea for the TMS team to launch some kind of set of components for FMX with "datasource-link" integration with TAureliusDataSet"

That way you will make all the cycle from designing the form till the server using TMS products. 

Thank you

We will consider it, but since you have TAureliusDataset, you can use it with livebindings, can't you? I mean, livebindings can bind controls to objects directly, but it also can use TDataset as a binding source, right? This way I believe it would be simple to use livebindings because the TDataset interface is a very "known" interface for the live bindings framework.

What I mean is, although I agree that the more demos the better, it's out of the scope of Aurelius to "teach" how live bindings work. If you use TAureliusDataset, I believe there is nothing specific about "livebinding+aurelius" you should know. It's just pure livebindings knowledge.

95% I agree with you, however try to use in FMX: TCombBox + TAureliusDataSet on the example above. I dont see how to do that... That is not only livebinding knowledge...


Sure I am knew to livebinding, I could be just not understanding it... however for the ComboBox binding I dont see how to solve using Aurelius.

In this sense, of teaching from the perspective of Aurelius what I meant.

For simple forms that map directly the field on the table to the FMX components I could make livebinding works fine with TAureliusDataset so far.

I don't know if or how livebindings support binding object properties. For example, suppose I want to use livebindings to set a TDatasource.Dataset property. I want to allow the user to choose from a list of existing TDataset objects and when the user chooses the desired dataset from the combo, the TDatasource.Dataset property is set with the choosen dataset. It's the same principle.

Hi Wagner,


I made a lot of tests and found some interesting things.,,,

First of all is that I could populate the Tcombobox and TComboEdit just fine using LiveBinding !!!

The members to be used:
SelectedValue
Item.Text
Item.LookupData

In fact, FMX got so many changes since XE2 and specially with ComboBoxes that turned to be simplier. I was looking to old examples, and FMX have many breaking changes.

However, there is one problem I don´t find a way to solve.

I should be binding the member "selectedvalue" from the combobox to the datasource field that would be receiving the result of the selection from the combobox.

I have tried connecting to the "Self" member on the datasource but it did not work.

Just remembering, I am trying to select the "UNIDADE" (TEntityUnidade from the code above) for my TEntityItemProduto.

Right now it seems to be the last thing that remains to have my first Aurelius application runs.

Actually I am already writing my new project directly, and expect to show it next week, since the result right now is so positive!

Do you have any clue on this?

Why connecting to Self member? You should connect to property Unidade, right?

This is what I was expecting, but I dont have it on the DataSet Listed to be connected and if I add the tag:


    [Column('UNIDADE', [], 0)]
    property  Unidade: TEntityUnidade read GetUnidade write SetUnidade;

It give me an error when loading the field on the dataset using the package:

"unexpected field type: TEntityUnidade"

I am doing something wrong on the class declaration tags, and I cannot see what is wrong. 


(my code remains the way is listed on the #1 post.

If you say it should list on the TAureliusDataSet the field UNIDADE (TEntityUnidade) for linking I believe the field for FORNECEDORES (TEntityFornecedores) should be added also. But any column declaration of them will give me an error when loading the bpl package on the TAureliusDataSet Field Loader. (yes I compile my package everytime to make sure)

That error happens when Aureluis can't find type info about TEntityUnidade. Is it a class? Is it mapped with [Entity] attribute? Are you sure it's not being removed by the linker?

In the listing there is no TEntityUnidade. In the listing you provided, only error I see is a missing [Id] attribute in TEntityItemProduto.

Maybe you should make sure you use all classes in your source code so that you guarantee the linker is not removing them.

I understand that... my generated package lists all the Entities that I have.


And this in particular is included and is not removed since the TComboBox is using it !!!

This TEntityUnidade is used on a second TAureliusDataset on the same Form, connected to a DataSetBinding and I use it to wire the connections to the TComboBoxes. I have the TEntityUnidade fields loaded on the dataset using the package either.

So, it should be recognized.

And my model layer is doing this: result.AsCriteria := Manager.Find<TEntityUnidade>;

and passing to the second TAureliusDataSet on the form as a ICriteriaCursor. 

So what is wrong???