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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to run a form event from another form.

Status
Not open for further replies.

davidb88

Technical User
May 3, 2012
5
GB
Hello,

I am using some product data management software that was written in VF6. The software allows me to add and run UDF code and form event code and I have managed to add some nice additional functionality.

The software is based around two forms, and some of the fields on form1 relate to calculated fields on form2.

I have a form event (instead of save) code on form2 which I want to trigger when saving form1, thus updating the calculated fields on form2. Form 1 and 2 are always active and I have tried using form2.save from form1, but it does not work.

Oddly, I have managed to call the 'after refresh' event on form2 from form1 using form2.refresh.

Any help would be appreciated.

Thanks,

David
 
What is form1.parentclass? Empty?

If not, and if you write code into form1.save() to call whatever
method of form2, then call DODEFAULT() before that within form1.save() to execute the predefiend save code.

Otherwise you override the save and don't save, thus also form2 will not refresh. That would explain it.

Bye, Olaf.
 
Hi Olaf and thanks for your reply

I think the parent class is empty.

Sorry, I am a bit of a novice...

Should the code be constructed like this?

CALL DODEFAULT(form2.save())

Thanks, David

 
If the parentclass property is empty there is no need to call DODEFAULT(). The nomenclature is different, doesn't matter.

I'm sorry, I'd need to know more about the concept of the application and adding UDFs to it. Are you working with VFP itself or does the application provide an interface to add code?

Do you have any kind of documentation about this extensibility feature you could share?

Bye, Olaf.

 
I do calls to other forms all the time basically you send form_name.procedure. However, you say you want to do calculations. Why use another form instead of a user defined method. That would normally be called with thisform.method. That should be faster.

If I have standard calculations I'd normally call them in a Prg with you go to with do prg with x,y,z

Call would normally be a VB command to me. While VFP and VB have extremely similar syntax it isn't identical.
 
An easy solution is to create an object which hangs on _screen, which holds the form objects as passed parameters.

_screen.addObject("_myHolder", "myholder")
* Do whatever to launch forms 1 and 2, and in their init code, use this:

*FormN.init()
_screen._myHolder.formN_checkin(1, thisForm)
_screen._myHolder.formN_checkin(2, thisForm)

And then you can always reference either one from either form by using:
LOCAL loForm
loForm = _screen._myHolder.get_formN(1)
IF !ISNULL(loForm)
loForm.whatever
ENDIF

...

DEFINE myHolder AS Custom
form1_object = .NULL.
form2_object = .NULL.

PROCEDURE formN_checkin
LPARAMETERS tnForm, toForm
DO CASE
CASE tnForm = 1
form1_object = toForm
CASE tnForm = 2
form2_object = toForm
* more references could be added here
ENDCASE

PROCEDURE get_formN
LPARAMETERS tnForm
DO CASE
CASE tnForm = 1
RETURN form1_object
CASE tnForm = 2
RETURN form2_object
* more references could be added here
ENDCASE
RETURN .NULL.
ENDDEFINE



Best regards,
Rick C. Hodgin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top