Paradox Community
Search:

 Welcome |  What is Paradox |  Paradox Folk |  Paradox Solutions |
 Interactive Paradox |  Paradox Programming |  Internet/Intranet Development |
 Support Options |  Classified Ads |  Wish List |  Submissions 


Paradox Programming Articles  |  Beyond Help Articles  |  Tips & Tricks Articles  


Passing Variables between Forms Using a Library - Part 2
Passing Multiple Variables
© 2001 Tom Krieg

Introduction

One way of passing a number of variables between forms which I've found very effective is to use the concept outlined in Part 1: Passing a Single Variable, but to pass a dynamic array instead of a single variable. Whilst the concept is similar, there are a number of modifications you'll need to make to the code in part 1.

When returning data, methods can only return one item of data, of a single type. For example, whilst a dynArray can be considered one (complex) item of data, the statements
method ReturnArray() DynArray[ ] AnyType
or
method ReadArray(DynArray[ ] AnyType)
will cause a syntax error when you compile your form or library.

You can avoid this error by creating a new type.
Type
VarArray = DynArray[ ] AnyType
endType
By using this new type, the statements
method ReturnArray() VarArray
or
method ReadArray(VarArray)
will NOT cause a syntax error.

Taking the first example (passing a single variable between forms) one step further by using this new VarArray type, we can pass many variables (of differing types) between forms using a single library call.


Library

Let's start with the library once more. In the Type method of the library, declare the new VarArray type.
Type
VarArray = DynArray[ ] AnyType
endType
In the library's Var method, declare the dynArray you wish to set and pass between forms. In this example I'll call this variable dynMyArray.
Var
dynMyArray VarArray
endVar
Next, you'll need to write the method which takes the array passed by a form and assigns it to the variable dynMyArray. I've called this method PassArray.
method PassArray(inputArray VarArray)
dynMyArray = inputArray
endMethod
Then you'll need to write the method which returns the array to any method or procedure requesting it. I've called this method ReadArray.
method ReadArray() VarArray
Return dynMyArray
endMethod

The Form Which Passes The Array

Let's begin by coding the form which passes the array to the library for other forms to access later.

In the Type method of the form, declare the new VarArray type.
Type
VarArray = DynArray[ ] AnyType
endType
In the Var method of the form, declare both the library and the array to be passed to other forms.
Var
CustomLib    Library
outputArray  VarArray
endVar
In the Uses method of the form, you'll need to declare an external call to an objectPAL library.
Uses objectPAL
PassArray(outputArray VarArray)
endUses
In the init event of the form, open the library. Remember to tidy up in the close event.
method init(var eventInfo Event)
doDefault
CustomLib.open("MyLibraryName")
:// where MyLibraryName is the name of your library
endMethod
When you want to pass the array to the library, assign whatever values you want to the various elements of the array outputArray.
outputArray["Name"] = "John Smith"
outputArray["Address"] = "John Smith's Address"
outputArray["Credit"] = Currency(JohnSmithsCreditLimit)
outputArray["Yes/No"] = Logical(False)
Now call the library method PassArray, passing outputArray as an argument.
CustomLib.PassArray(outputArray)

The Form Which Reads The Array

Next, we'll code another form to read the array from the library.

Again, in the Type and Var methods of the form, declare both the library and the array to be read.
Type
VarArray = DynArray[ ] AnyType
endType


Var
CustomLib    Library
inputArray   VarArray
endVar
In the Uses method of the form, you'll again need to declare an external call to an objectPAL library.
Uses objectPAL
ReadArray() VarArray
endUses
In the init event of the form, open the library. Remember to tidy up in the close event.
method init(var eventInfo Event)
doDefault
CustomLib.open("MyLibraryName")
;// where MyLibraryName is the name of your library
endMethod
Now, wherever you want to read the variables passed in a dynArray by another form, simply read the dynArray and break it up into its constituent components.
inputArray = CustomLib.ReadArray()
CustomerName = inputArray["Name"]
CustomerAddress = inputArray["Address"]
CreditLimit = inputArray["Credit"]
GiveCredit = inputArray["Yes/No"]
I've assumed that the variables
CustomerName String
CustomerAddress String
CreditLimit Currency
GiveCredit Logical
have been declared elsewhere.


Summary

This is a simple way of passing a number of variables of different types between one form and another.


Part 1 - Passing a Single Variable


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.