Show/Hide Toolbars

TMS Aurelius Documentation

You can use lookup fields with TAureliusDataset, either at design-time or runtime. Usage is not different from any TDataset.

 

One thing it's worth note, though, is how to use lookup field for entity fields (associations), which is probably the most common usage. Suppose you have a TInvoice class with a property Customer that is an association to a TCustomer class. You can have two datasets with TInvoice and TCustomer data, and you want to create a lookup field in Invoices dataset to lookup for a value in Customers dataset, based on the value of Customer property.

 

Since "Customer" is an entity field in Invoices dataset, you need to lookup for its value in the Customers dataset using the "Self" field, which represents a reference to the TCustomer object in Customers dataset. The following code illustrates how to create a lookup field in Invoices dataset to lookup for the customer name based on "Customer" field:

 

// Invoices is a dataset which data is a list of TInvoice objects

// Customers is dataset which data is a list of TCustomer objects

 

// Create the lookup field in Invoices dataset

LookupField := TStringField.Create(Invoices.Owner);

LookupField.FieldName := 'CustomerName';

LookupField.FieldKind := fkLookup;

LookupField.Dataset := Invoices;

LookupField.LookupDataset := Customers;

LookupField.LookupKeyFields := 'Self';

LookupField.LookupResultField := 'Name';

LookupField.KeyFields := 'Customer';

 

Being a regular lookup field, this approach also works with componentes like TDBLookupComboBox and TDBGrid. It would display a combo with a list of customer names, and will allow you to change the customer of TInvoice object by choosing the item in combo (the field "Customer" in Invoices dataset will be updated with the value of field "Self" in Customers dataset).