How tos

How To pass parameters between objects (forms, reports, ...)?

Author
Luc Van Dyck
Date
26/05/2003
Size
4,93 KB
Downloads
2621
Rating
43211
Popularity
Downloaded 4 times in the last two weeks
This example uses 2 forms:

- Form1 asks for a name and two decimal values

- After clicking the "Call Form2" button, these variables are passed to Form2, where they are displayed.

- After clicking the "Return to Form1" button, focus is placed again on Form1 and the result of the calculation (decimal1 + decimal2) is displayed.

This is the code behind the "Call Form2" button of Form1. Form2 is defined as a variable (frmForm2), otherwise it isn't possible to call the functions on that form.
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;

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 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);

The same idea can be used to transfer some data to a report or dataport.