| RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Essentials|Books|Link Back |
| Communicating Between Forms | |||||||||||||||||||||||||
| Page 2: Getting the values from another form | |||||||||||||||||||||||||
Now, knowing whether the user wants to accept or reject what occurred on the child form, the calling form can react by using the information from the child form or ignoring it. Let's see how...
Events to look at for ModalResult (in Forms.pas):
function TCustomForm.ShowModal: Integer; ModalResult Constants from Controls.pas
const Sometimes you will need to get more than one piece of information back from a form, but let's start simple. The following example shows how to get the value stored in a TEdit (Name : 'Edit1') Text property if the user pressed the Ok button on the child form (Name: 'frmSimpleString').
To keep the example short we are just checking for an Ok response and ignoring negative responses. When the user presses the OK button (its ModalResult is set to mrOk) the following code reads the value of an edit control, Edit1, on the called form and then destroys the form. In a real application you might need information from several components on the called form. We could have streamlined the code a little more by adding code to let the user choose whether to continue with closing the form or aborting back into the called form:
On the called form we add a procedure GetThatString to interrogate the user modally to find out whether the user wants to continue or abort the current operation. For elegance, the Case statement is used rather than a chain of nested IF..THEN..ELSE statements, i.e.
Retrieving a string is simple enough but, often, you will need much more than a simple string. Methods for getting a lot of information back from a called form include using an array, a TList, a StringList, or records. The logic used to determine if the user wants to return information remains the same, only the means of storing it varies. To show how this might be done, I will use a record to store user input for retrieval once the user presses OK in the called form. To make things interesting, we will use an array of records so that multiple pieces of information can be returned from the called form!
Before digging into an example, lets go through a short lesson of record types for those programmers that may have not worked with records: "Records in Delphi".
Next page > Moving records of data between two forms > Page 1, 2, 3
A Beginner's Guide to Delphi Programming: Next Chapter >> |
|||||||||||||||||||||||||
All graphics (if any) in this feature created by Zarko Gajic.
| More Delphi |
|
· Learn another routine every day - RTL Quick Reference. · Download free source code applications and components. · Talk about Delphi Programming, real time. · Link to the Delphi Programming site from your Web pages. · Tutorials, articles, tech. tips by date: 2003|2002|2001|2000|1999|1998 or by TOPIC. |
| Stay informed with all new and interesting things about Delphi (for free). |
|
|
| Got some code to share? Got a question? Need some help? |

