1. Tech

Your suggestion is on its way!

An email with a link to:

http://delphi.about.com/od/database/l/aa090401b.htm

was emailed to:

Thanks for sharing About.com with others!

Lookup!
Page 2: New...lookup field.
 More of this Feature
• Page 1: On lookup fields
• Page 3: DBLookupCombo
• Page 4: DBGrid.PickList
 Join the Discussion
"Post your views and comments to this chapter of the free Delphi database Programming Course"
Discuss!
 Related Resources
• free DB Course.TOC
• Coloring the DBGrid
• Using Data Controls
• more Database articles

   New ... lookup field
To crete a new field object you have to invoke the Fields editor for a dataset. Double click the ApplicationsTable and right click it to have a pop up menu displayed. Pick "New field..."

Fields editor

The idea is to set the value for the Author field by picking it's email. I know this does not make much sense, but it will bring the lookup idea closer. In the New field form fill the boxes as on the picture below. We create a new AEmail field for the ApplicationTable dataset. As you can see from the picture, there are few very important properties you have to understand prior to working with lookup fields.

.Field Name is the name of the lookup field. Set it to AEmail.
.Dataset identifies the dataset that contains lookup values (Authors).
.KeyFields is a field in the Applications dataset we are setting through a lookup.
.Lookup Keys is a field in the lookup dataset (Authors) to match against the KeyFields.
.ResultField is a field in the lookup dataset to return as the value of the lookup field you are creating.

New field

That's it. No code required. Start your project (or set Active property for both tables to True) and you can see that DBGrid, in the AName fields column, has a combo box with author emails. As you pick an email the corresponding author field changes. We are looking up an authors email to change the author. Note that AEMail is a read-only field.

Lookup field in a DBGrid

Note: the combo box in the cell of a DBGrid has nothing with the PickList property of Grid's column. This will be explained later in this chapter.

Next page > The DBLookupComboBox looks up > Page 1, 2, 3, 4

DB Course Next Chapter >>
>> Compacting an Access database with ADO and Delphi - DB/16

©2014 About.com. All rights reserved.