You are here:
About>Computing & Technology>Delphi Programming
About.com

FREE Newsletter


See Online Courses
 
Delphi Programming
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

Your Guide, Zarko GajicFrom Zarko Gajic,
Your Guide to Delphi Programming.
FREE Newsletter. Sign Up Now!

    Topic Index | Email to a Friend

Our Story | Be a Guide | Advertising Info | Work at About | Site Map | Icons | Help
User Agreement | Ethics Policy | Patent Info. | Privacy Policy | Kids' Privacy Policy

©2005 About, Inc., A part of the New York Times Company. All rights reserved.
Around About

New Video iPod - Review POLL: Must-Have Gadgets VIDEO: Portable Gaming VIDEO: Choosing a TV Hugh Hefner's Life

What's Hot

Delphi Drawing Snowflakes over your Desktop ScreenLeftStr functionDelphi Keyboard ShortcutsA more powerful Delphi Form - page 1/2Uploading files to a web server with ASP.Net

Headlines

Understanding Delphi Variable Scope ARTICLES :: The term scope refers to the availability of...Inside the EXE eCourse :: Storing more that just code in the application...Drawing Snowflakes All Over your Desktop Screen FUN :: It's time for a little winter joy! Amaze...Delphi IDE (Code Editor) Keyboard Shortcuts TIPS :: Every once in a while I'll come across...