
Microsoft Dynamics NAV Most Valuable Professional Luc Van Dyck is webmaster of the Microsoft Business Solutions online community Mibuso.com. In addition to providing helpful discussion forums and downloads, mibuso.com features a collection of tips for Microsoft Dynamics NAV developers. This page is reprinted with permission from mibuso.com. In this tip, I will demonstrate how to pass parameters from one form to another. For the sake of this example, I’ll name the forms Form1 and Form2. In this example, Form2 will make a simple mathematical calculation, and Form1 will retrieve the result. Here's how it works: 1. | Form1 asks for a name and two decimal values. Enter the data requested, and click the Call Form2 button. 
| 2. | Clicking the Call Form2 button passes these variables to Form2, where they are displayed. 
| 3. | Clicking the Return to Form1 button returns the focus to Form1, where the result of the calculation (Decimal 1 + Decimal 2) is now displayed. 
Here is the code behind the Call Form2 button of Form1. Form2 is defined as a variable (named frmForm2). Otherwise, it wouldn’t be possible to call the functions on Form2. OnPush() CLEAR(frmForm2); frmForm2.fctSetName(txtName); frmForm2.fctSetDecimal1(decNumber1); frmForm2.fctSetDecimal2(decNumber2); decResult := 0; IF frmForm2.RUNMODAL = ACTION::Close THEN BEGIN decResult := frmForm2.fctGetResult; END; |
And here are the functions of Form2, which accepts the parameters and returns the result of the calculation. The parameters are stored in global variables so that they can be used in the form. fctSetName(ptxtName : Text[30]) //fctSetName
txtName := ptxtName;
fctSetDecimal1(pdecNumber1 : Decimal) //fctSetDecimal1
decNumber1 := pdecNumber1;
fctSetDecimal2(pdecNumber2 : Decimal) //fctSetDecimal2
decNumber2 := pdecNumber2;
fctGetResult() : Decimal// fctGetResult
EXIT(decNumber1 + decNumber2); That’s all there is to it. You should now be able to successfully pass parameters between your own objects. Luc Van Dyck is a Microsoft Dynamics NAV Most Valuable Professional (MVP). He works as a Software Consultant for Mindstone NV in Belgium. He is also webmaster of Mibuso.com, which provides a platform for users and developers of products from the Microsoft Dynamics family to exchange ideas, tools, and how-to's, and to find business partners and products. © Luc Van Dyck and mibuso.com. December 2004.
|