| RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Books|Link Back |
| Communicating Between Forms | |||||||||||||||||||||||||||||
| Page 3: Moving records of data between two forms | |||||||||||||||||||||||||||||
Back in the "Records in Delphi" article, a sample code was presented demonstrating pressing a button to populate the array of records with dummy information, then display the records in the memo control. This should give you a starting point to working with record arrays. The main thing to remember about the example is that we created a record type, supplied the name of TPerson, then created a local variable called MyPeople which is an array of type TPerson which can hold three (3) rows of information. Let's use the idea to present a data entry form to a user, allow data to be entered about several people before returning to the main form to process it. Use the next piece of code to call the secondary form for the data entry:
When the user invokes the event, the main form creates the data entry form, shows it, then checks to see if there were any people entered into the people array. The variable PersonCount in the data entry form is incremented each time a new person is added to the array of records. The following code is placed into a simple unit (Delphi IDE Main Menu: File -> New -> Unit) so that any form in the project can see the People record along with a constant used to limit how many elements (records) can be used in the array of records.
In the public portion of the called form's declarations we declare an array of records and a variable for keeping track of how many records the user has entered.
In the Create event of the data entry form the following code is called to clear all edit controls so that the form starts up with a clean slate. Each time the user accepts a screenful of people information the ClearEdit procedure is triggered:
The next code fills a row of data in the people array and increments the row counter. The counter is checked to ensure that the number of rows keeps within the fixed boundaries of the array of records.
Using this example you can return just about any type of data, in either single or multiple rows. To recap, you can detect how a modal form was closed and get information back in several ways. Keep in mind there are other ways to accomplish returning information from modal forms. Detour timeThe last thing a programmer needs when searching for assistance in a help file or manuals is an incorrect example of how to do a particular task. I caught one in D4 after writing this article, to do with "Passing additional arguments to forms", listed under "forms" in Delphi help. Shown below are the key pieces:
Don't feel bad if you can not figure out what's missing/wrong with the example. This code was posted on Borland's news group as a solution for a posted question. Instead of trying to figure out the errors, look at the correct code:
Some exercises for you...This time an easy one: download the example Delphi project for this chapter and try out the code without having to type it in yourself. The source units also expand some concepts beyond the scope of this chapter and provide more technical explanations. To the next chapter: A Beginner's Guide to Delphi Programming If you need any kind of help at this point, please post to the Delphi Programming Forum where all the questions are answered and beginners are treated as experts. First page > Finding out how a modal form was closed > Page 1, 2, 3 v |
|||||||||||||||||||||||||||||
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? |
