Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with Parameters

Status
Not open for further replies.

admdev

Programmer
May 17, 2006
56
US
Hi all,

Hope you can help!

I am sending a parameter from Form A to Form B as such.

NEWOBJECT('frmtest', 'testclass.vcx','',parameter)

While in Form B, I am updating the value and I would like to send it back to Form A.

Could anybody help with this?

Thanks in advance.
 
Use parameter object instead of the static parameter. This way you can change its properties in any form and they would be accessible.

e.g.

loParm = createobject('custom')
loParm.AddProperty('myProp','')

formA calls formB with this loParm, formB can modify its properties and the changes would be now accessible in formA.

 
Will this object be part of FormA?

Thanks.
 
One way to do this would be to pass the parameter by reference . To achieve that, put an ampersand in front of it (in the calling code):

NEWOBJECT('frmtest', 'testclass.vcx','',&parameter)

Then, in Form B, just update the value in the usual way. However, you must do that in the Init of Form B.

Also, none of these methods will work unless Form B is modal.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
I frequently send parameters to forms and recieve a returned value from the called form when it closes. The called form assigns a vaule to ThisForm.Tag. In the UNLOAD event of the called form ( your form B ) I place:
RETURN ThisForm.Tag
Here is a CODE SAMPLE from one of my functions where a value is returned to local variable cChoice.
Code:
DO FORM FORMS\YesNo WITH cText,lDefault , nLeft , nTop  TO cChoice

IF	cChoice = 'YES'
      lReturn = .T.
ELSE
	lReturn = .F.
ENDIF
RETURN lReturn

I hope this helps

Jim Rumbaugh

 
I frequently send parameters to forms and recieve a returned value from the called form when it closes.

Another way would be with Modal as well as Modeless forms and you dont have to wait till it closes:

In the called (child) form's INIT()
lParameters pWhoCalled
with this
.addproperty("WhoCalled",pWhoCalled)
.....
.....
endwith

Now in the calling (parent) form:
do form <<childform>> with thisform

Now from the child form you can access any event, method & property with
Thisform.whocalled.<< any thing>>

There are a lot of variations to this. If the form is not Modal and you want to access the child form while its open from the parent:
Create a property in the parent form called "child form" or whatever before you call the child form.
In the INIT() of the child form:
Thisform.whocalled.childform = this

Now you can have a 2 way Conversation

Again: this is to give you an idea, you will have to fine tune
 
Thanks guys for all your suggestions.

I will try the suggested solutions and get back here to post what best worked for me.

Thanks.
 
Thanks for your help guys!

What I am doing is what ilyad suggested. I am passing the form A as a parameter to Form B. Within form B I am able to modify any properties on form A.

Thanks.
 
You're welcome :) Didn't you forget to mark helpful responses? :)
 
Ilyad,

Didn't you forget to mark helpful responses?

Could I respectfully point out that that remark is contrary to Tek Tips policies and etiquette. Whether a member chooses to mark a post as helpful is entirely a matter for them to decide. The management frowns on messages that solicit such a response.

I hope you don't mind me pointing this out. I've noticed you've posted a similar remark in other threads. You are an active member of this forum, and forum members rightly value your contributions. I wouldn't want anyone on the management side to give you a bad time over this.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
I like opticalman's solution, where there is no need for helpers to carry the gift from UNLOAD event. As UNLOAD is the official gift distributor.
 
Mike,

jsu one thing, you meant @, not ampersand, for sending a parameter by reference.

This could work too, but has it's disadvantage, if passing the parameter to a form, because that parameter get's out of scope, after form Bs init has run.

passing formA as reference to formB is a good solution, if formB runs modal. If not, you could get problems releasing formA, especially if you store that reference to formA in a property of formB. Then a seperate Parameter object has some advantages. Since VFP8 you can make use of the lightweight object class "empty".

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top