As said the natural way to share things is a table.
If you have time for the whole background:
There is the topic of passing parameters by value vs by reference, eg:
Code:
* Passing by value
LOCAL lnNumber
lnNumber = 1
lnNumber = Increment(lnNumber)
? lnNumber && prints 2
Function Increment(tnNumber)
Return tnNumber+1
Code:
* Passing by reference
LOCAL lnNumber
lnNumber = 1
Increment(@lnNumber)
? lnNumber && prints 2
Procedure Increment(tnNumber)
tnNumber = tnNumber+1
The @ extends the scope of the variable to the called procedure, though the procedure still has it's own name tnNumber (notice the t instead of l) for the variable in its code. It's not the procedure but the caller deciding with the @, what memory variable the called procedure acts on with its internal variable name tnNumber.
That works universally, but a form isn't a function or procedure with visual interaction, so if you add @ to your parameters what happens is only the first INIT event of the form with its LParamerters line would act on the passed-in variable by referencing the same memory. The rest of the form - and that is important to you - doesn't know about the init parameters of the form. The form parameter are there to influence the form state or behavior at its beginning, not to act as two-way in and out parameters.
So to act on the passed in values, no matter of you pass them in by reference or value, you need to copy their value to something persisting in the whole life scope of the form. And yes, you can pass something back, to yet another variable the caller specifies in its call as TO clause, TO lcTargetVariable. But that's only possible with modal forms, which in itself is a limitation I would not like, even though it makes the user focus on this current workflow step of picking something. And in that case, as the RETURN something goes back into another variable, you don't have that shareed variable thing at all, unless the init would already give you the feedback you want, but that would never be the intention of the form - to have a result before it is even shown.
You argue from the point of view a variable is the best thing to store a single value, but due to the limitations of passing by reference you're bound to copy your values around multiple time:
1. copy the variable value from the caller to the form init parameter
2. copy the init parameter to a form.property or anything else persistent in the lifetime of the form
3. copy that property or any form element value as return value in the Unload event
4. copy from the target variable back into the original caller variable you wanted it to be, or even copy it somewhere else, into a table field.
And besides this copying, you also have at least 3 names for the same thing, the caller variable, the init parameter name and the child form property or control name.
Using a cursor in the shared datasession, the value we talk about always is in one field of one record of that cursor, referenced by the one single name this has. The value never travels anywhere, it never needs to be copied. Though it takes only split seconds to copy even large values in memory, is it really more natural to do so instead of simply sharing a cursor?
The cursor also allows you to share as many as 254 fields in one record and you can have multiple records, too. Parameters are limited to 27. And Unload only returns 1 value.
There is one more thing you can do also without the @, you can pass objects or variables that refer to objects. Both just means passing the object reference, there is no passing of objects by value, so they don't get copied. Not, that the act of copying is the bad thing, but that has the advantage you act on the original. But you need the same steps as with variable, you need to store the passed object reference to a child-form property, etc. You don't need the RETURN in the Unload, as you can simply act on object properties and thereby let a picked choice come back to the parent also still knowing that same object, but it still is not as easy as sharing data, what a database system is made for, is it?
Bye, Olaf.