![]() |
![]() |
|
![]() |
Returning Multiple Items with formReturn() © 2001 Kasey Chang Introduction Wait/FormReturn is the way in OPAL to get more information from dialog boxes. A typical use would probably look something like this: var strGetSomeValue string frmGetSomeValue form endvar frmGetSomeValue.open(":dialog:GetSomeValue") strGetSomeValue=frmGetSomeValue.wait() frmGetSomeValue.close()Note that wait() can only return one value. So what happens if you need multiple values from the dialog box? There are three approaches: direct-read, indirect-read, and pass-multiple. Direct-read Direct-read basically means you read the value directly from the form's fields. Here's an example: var strGetSomeValue1, strGetSomeValue2 string frmGetSomeValue form endvar frmGetSomeValue.open(":dialog:GetSomeValue") strGetSomeValue1=frmGetSomeValue.wait() if strGetSomeValue1="OK" then strGetSomeValue2=frmGetSomeValue.SomeOtherField endif frmGetSomeValue.close()In this example, the value returned in wait() is mainly used as a flag to indicate whether to read from the form or not. The disadvantage of direct-read is that if there's any change in the dialog, you may have to redo the calling code. If the dialog is called in multiple places, the code change can be quite significant. Indirect-read The Indirect-read is a variant of the direct-read method. Basically, you create some custom methods in the dialog box form level that return the appropriate values. You'll have to declare the custom methods to use them in the calling code, but you can then change the fields in the dialog box without affecting the calling code as long as the custom method returns the right data. For example: uses ObjectPAL getSomeMoreValues(val1 string, val2 string) logical endUses var strGetSomeValue1, strGetSomeValue2 string frmGetSomeValue form endvar frmGetSomeValue.open(":dialog:GetSomeValue") strGetSomeValue1=frmGetSomeValue.wait() if strGetSomeValue1="OK" then frmGetSomeValue.getSomeMoreValues(strGetSomeValue1, strGetSomeValue2) endif frmGetSomeValue.close()This way, this code doesn't care what the fields are called in the dialog box, just that getSomeMoreValues returns the right stuff. The disadvantage is that it takes more time to write this. However, Indirect-read also makes it easy to add additional functionality without breaking existing code. If you need to return additional parameters, just create a new custom method that includes all the fields you need. The existing code can continue calling the old custom method. Pass-multiple Pass-multiple, on the other hand, simply squeezes the different parameters together and returns it into the same formreturn. This involves a bit of coding on both the form (executing the formreturn) and the code (interpreting the returned result). On the returning end, the formreturn code would probably look like: formreturn(fldName'value+"|"+fldSSN'value)Let's say the dialog box returns this (without the quotes of course) via formreturn: "JOHN DOE|123-45-6789"Then the code to process becomes something like this: var strGetSomeValue1, strGetSomeValue2 string frmGetSomeValue form arTemp array[] string endvar frmGetSomeValue.open(":dialog:GetSomeValue") strGetSomeValue1=frmGetSomeValue.wait() frmGetSomeValue.close() strGetSomeValue1.breakApart(arTemp,"|") strGetSomeValue1=ar[1] strGetSomeValue2=ar[2] ;note: you can use match() to separate the values tooThe pass-multiple method is good for quick retrofit work when you just need to return one more field from that dialog box meant for one field only. It can be done fairly quickly. However, it's quite unwieldy when you deal with more than a handful of parameters, and it's best only to use strings, as dates and such can be affected by different formatting options. Summary In conclusion, there are always multiple ways to do the same thing in OPAL. Each method to pass parameters here offers its own set of pros and cons. If you have the time, then go for the indirect-read method, as it is self-documenting, and you can always access the dialog contents directly (bypassing the custom method) if you have to. The pass-multiple method should be reserved for a "must-have-it-now" type of situation where you need the job done rather than done right. Discussion of this article |
![]() Feedback | Paradox Day | Who Uses Paradox | I Use Paradox | Downloads ![]() |
|
![]() The information provided on this Web site is not in any way sponsored or endorsed by Corel Corporation. Paradox is a registered trademark of Corel Corporation. ![]() |
|
![]() Modified: 15 May 2003 Terms of Use / Legal Disclaimer ![]() |
![]() Copyright © 2001- 2003 Paradox Community. All rights reserved. Company and product names are trademarks or registered trademarks of their respective companies. Authors hold the copyrights to their own works. Please contact the author of any article for details. ![]() |
![]() |
|