|
|
|
Delphi - Using and Creating Lookups (2)
In our example we have used ADO to retrieve the information from our database. We will not touch on the techniques used to retrieve the data in this example. Notice how we have positioned 3 buttons below the data grid, 'Refresh', 'Select' and 'Cancel'. Each of these buttons performs different tasks for the Lookup form. It should be obvious what the refresh does so we wont look at that. However the code contained in the Select and Cancel events is very important.
Ok lets look at Select button first. The 'Select' button is used when the user has highlighted a record in the data grid (we recommend switching the RowSelect property of the data grid to True) and wants to return its value back to the calling form. So in this case we want the Delphi code to close the Lookup form and preserve the selected customer values (customer name, address etc..). To achieve the closing of the Lookup form we must code the following in the 'OnClick' event of the Select button:
This command will close the Lookup form and instruct the calling form that the selected value in the Lookup was accepted.Alternatively if the user clicked the Cancel button we want to close the Lookup form and tell the calling form that a value was not accepted in the Lookup. In this case we use the following in the OnClick event of the Cancel button:
So now we have touched on how the Lookup form is designed and which options we should give the user, lets take a look at how we store the values selected by the user.
A very common feature of Object Oriented programming is the 'Property' type. We can create Properties that allow other forms in our application to read and write values that are contained in our class. In this case we want to create Properties that are part of our Lookup form class. We also don't really want our other Delphi classes and forms to change the value of these properties so we will usually create them as Public and Read only. To create a property we must first create a private Function that the Property is related to:
|
|
Featured |
Other popular Delphi resources. Why not try them for yourself?
|
|
Delphi Knowledge Base. Best practices, walkthroughs, tutorials, component advice and more. Solutions and professional designs for Delphi 4, Delphi 5, Delphi 6 and Delphi, 7. Word COM, Excel COM, Outlook COM including code examples for Word OLE, Excel OLE and Outlook OLE. Automating Outlook to create MailItem and send attachments in Delphi. ActiveX, Com. ADO Data Architecture, TMS component pack walk through and code examples. Using Developer Express and example walkthroughs. Date & time conversion routines, video playback and frame manipulation. COM articles, papers, tips, techniques and hints. How to create Word reports and excel spreadsheets using Delphi code and OLE automation. Understanding Delphi encryption and using ciphers, with source code examples of Blowfish, Twofish, and Rijndael. Securing application data and confidential information using open source encryption components. Free encryption dll component. Accessing and managing MS Excel sheets with Delphi. How to retrieve, display and edit Microsoft Excel spreadsheets with Delphi automation. Accessing and managing MS Word documents with Delphi. How to retrieve, display and edit Microsoft Word documents using Delphi automation. Read and write Excel spreadsheets using Delphi code. How to read and write registry entries using Delphi code. Source code examples using Delphi 5, Delphi 6 and Delphi 7. Working with VCL Developer Express components. How to apply grid styles and themes to Delphi applications. Using image columns and shading to improve the grid and treeview appearances. Including examples from ExpressQuantumPack, for Delphi, ExpressPack for Delphi. Developer guides for Developer Express components. All our articles are written by our senior Delphi professionals to help you get the best from your legacy Delphi applications |
|