OUTPUT PARAMETER

Posted by Roger Blanchard on 27-Oct-2008 08:43

I am sure this is a dump question but here goes. I am calling a CLASS and have defined an INPUT-OUTPUT PARAMETER. As a test I assign the value of the parameter to 50 before the NEW statement as shown below.

iReturnCode = 50.

rUserSignOn = NEW UserSignOn(INPUT-OUTPUT iReturnCode ) .

WAIT-FOR Application:Run(rUserSignOn).

MESSAGE "After calling UserSignOn..iReturnCode=" iReturnCode

-AS ALERT-BOX.

Now in my CONTRUCTOR of the called CLASS I display the value of the PARAMETER and it is what I set in the calling procedure (50).

CONSTRUCTOR PUBLIC UserSignOn (INPUT-OUTPUT piReturnCode AS INTEGER ):

THIS-OBJECT().

MESSAGE "constructor..piReturnCode=" piReturnCode

VIEW-AS ALERT-BOX.

END CONSTRUCTOR.

I have buttons on the form and when clicked they will update the value of the PARAMETER and close the object. The issue is the value is not returned to the calling procedure. As a test I update the value of the PARAMETER in CONTRUCTOR and then the proper value is returned to the calling procedure.

What am I doping wrong?

METHOD PRIVATE VOID btnCancel_Click( INPUT sender AS System.Object, INPUT e AS System.EventArgs ):

ASSIGN piReturnCode = 1.

MESSAGE "cancel..piReturnCode=" piReturncode

VIEW-AS ALERT-BOX.

THIS-OBJECT:CLOSE().

RETURN.

END METHOD.

All Replies

Posted by Thomas Mercer-Hursh on 27-Oct-2008 11:05

I got lost somewhere in the middle, but are you suggesting that you have user input in the constructor? Please say no.

Posted by Roger Blanchard on 27-Oct-2008 11:09

No. I added a message for debugging purposes displaying the value of the parameter to make sure it was correct.

The issue appears to be no matter what I set this INPUT-OUTPUT parameter to be in the CLICK event of a button it has no effect on the value returned to the calling procedure.

Posted by Thomas Mercer-Hursh on 27-Oct-2008 11:14

But, if the input-output parameter is in the constructor, it is returned when the object is new'd. What is it that you are doing in the constructor that you expect it to change? I'm not getting where the clicking is happening in relation to the new.

Posted by Admin on 27-Oct-2008 11:16

I was struggeling at te same point at Thomas did...

The issue appears to be no matter what I set this

INPUT-OUTPUT parameter to be in the CLICK event of a

button it has no effect on the value returned to the

calling procedure.

That's because the OUTPUT parameter of the constructor is returned directly at the NEW to the caller. The Button Click handler runs while in WAIT-FOR state. That is always after the constructor.

A suggestion: Run the Dialog as a modal dialog (using :ShowDialog method). Have the value you'd like ot return to your program available as a property. Your code would look like this:

DEFINE VARIABLE oRes AS System.Windows.Forms.DialogResult NO-UNDO.

oForm = NEW UserSignOn (). /* NO OUTPUT HERE! */

WAIT-FOR oForm:ShowDialog() SET oRes .

IF oRes:ToString() = "OK" THEN

MESSAGE oForm:ReturnValue . /* This is your property */

Posted by Roger Blanchard on 27-Oct-2008 11:32

Let me give that a try.

Thanks.

Posted by Roger Blanchard on 27-Oct-2008 11:33

Thanks for the info.

Posted by Roger Blanchard on 27-Oct-2008 14:31

This worked great. Thanks for the help Thomas and Mike.

Posted by Thomas Mercer-Hursh on 27-Oct-2008 14:47

I'm glad that you got a solution ... but hope even more that you understand why the solution lay in that direction. There are a couple of different things you could have done to make it work, but the key to getting it right going forward is to make sure that you are clear about what should be happening when, i.e., that nothing you did after the new was going to impact that return parameter; only something done in the constructor could impact that.

Since you are happy, you might doll out some of those answer points, since you set it up as a question.

This thread is closed