How to create lookup fields using XDataClient?

Hi Wagner,

I'm having trouble creating lookup fields using XDataClient.

I have an Invoice object that references a Client object, ok.

I use the following command to return the list of Customers;

adsCustomer.SetSourceList (FXDataClient.List <TCustomer> ('$ orderby = Name desc'));

Then I use this command to return the Invoice list:

adsInvoice.SetSourceList (FXDataClient.List <TInvoice> ('$ orderby = ID'));

I can not do the Lookup, because each command above returns a different reference to the Custumer object.

How do i do the two above commands return the same reference to Client objects?

Indeed that's how it is now. You would have to manually manage to get the same instances of TCustomer in both lists. We're investigating a way to make the lookup work via ID of the instances instead of the references. But still not available.

Do you have any tips on how to do this management in an easier way?

You could use TObjectMap class declared in Aurelius.Engine.ObjectMap.pas unit. It handles the mechanism of keeping a single instance of an entity with same id, and has helper methods for that.


Is there any example of how to do this management using the TObjectMap class?

Iterate through all Invoices and add its customers to object map:

for Invoice in Invoices do
  if not Map.IsIdMapped(Invoice.Customer) then 

Do exactly the same for the customers returned in List<TCustomer>.
Then get the final list of customers using Map.GetList, to provide it to the dataset:

adsCustomer.ObjectClass := TCustomer;
adsCustomer.SetSourceList (Map.GetList);