Lookup Fields
In the TDBGrid, your application shows the key of the priority record that indicates the priority of the task. It would be better to see the name of the priority instead of its ID. Just as with local data, you can set this up in Data Abstract using a lookup field.
When you created the project, in addition to selecting the Tasks table from the schema, you also selected the Priorities table and you should already have the tbl_Priorities and ds_Priorities components in the DataModule.
Setting up a Lookup Field
In the DataModule, select Add LookUp Field from the tbl_Tasks components context menu.
Set the ds_Priorities component as the lookup source in the Lookup field editor. Select the ID field as the field to look up using the Priority field as the key.
Give the lookup field the name PriorityName. Click Add Button to create the lookup field.
Change the Priority column in the DBGrid on the client form to now use the PriorityName field. Because the lookup field carries its own display label, the grid would replace the column heading with that label once the data is loaded. To keep a heading of your choosing, set the column's Title.Caption explicitly (for example to Priority).
For the lookup to resolve at run time, the tbl_Priorities table also needs to be open, so update the LoadData method in the DataModule to open it alongside tbl_Tasks:
procedure TClientDataModule.LoadData;
begin
tbl_Priorities.Close;
tbl_Priorities.Open;
tbl_Tasks.Close;
tbl_Tasks.Open;
end;
Testing the Lookup Field
When you run your application now, instead of seeing the value of the priority field from the task record in the Priority column, you should see the appropriate name value from the corresponding record in the Priorities table.


