Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Inside Form1.cmdDoIt.Click:
DO FORM Form2 WITH "any value you want", "Any other value you want"
Inside Form2.Init:
LPARAMETERS pcParam1, pcParam2
* Here, we can do whatever we need to
* with the parameters we were given, such as:
THISFORM.Caption = pcParam1
* It's usually good practice to make your code
* safe from mistaken calls... better to have an
* incorrect label than a crash!
IF VARTYPE(pcParam2)='C'
THISFORM.lblWelcomeMessage.Caption = pcParam2
ENDIF
Inside Form1.cmdDoIt.Click:
LOCAL lcResult
DO FORM Form2 WITH "any parameter" TO lcResult
Inside Form2.Init:
LPARAMETERS pcParam1
IF VARTYPE(pcParam1)='C'
THISFORM.Caption = pcParam1
ENDIF
Inside Form2.Unload:
LOCAL lcResult
* Calculate what value you need to return, then return it:
IF THISFORM.I_Am_Happy
RETURN .T.
ELSE
lcResult = "This is a bad value: "+TRANSFORM(THISFORM.I_Am_Happy)
RETURN .T.
ENDIF
Inside Form1.cmdDoIt.Click:
LOCAL loForm2
DO FORM Form2 NAME loForm2 WITH THISFORM
loForm2.Caption = "I can change whatever in Form2 I want!"
Inside Form2.Init:
LPARAMETERS poForm1
THISFORM.lblWelcomeMessage.Caption = "I was called by "+poForm1.Caption
*If you create a custom property in Form2 called "FormThatCreatedMe" you can:
THISFORM.FormThatCreatedMe = poForm1
* HOWEVER, Form1 will not be able to release until this reference is Cleared.
* This is OK if Form2 is Modal, because it will be sure to clear before returning
* to Form1.cmdDoIt.Click; But if Form2 is ModeLESS, then this creates a Mess!
* BUT, Throughout the rest of Form2's methods, Form1 can be referred to
* as THISFORM.FormThatCreatedMe.{any property or method on form1}
In Main.PRG:
* This is assuming Form1 and Form2 are NON MODAL
DO FORM Form1 NAME goForm1
DO FORM Form2 NAME goForm2
In ANY METHOD of Form1, such as Form1.cmdDoIt.Click:
goForm2.Caption = "Ha Ha, I changed your Caption!"
goForm2.CustomMethod && Run a custom method of Form2
In ANY METHOD of Form2, such as Form2.cmdDoIt.Click:
goForm1.Caption = "I can change yours, too!"
goForm1.Release && Close Form1
Inside Main.PRG:
DO FORM Form1
DO FORM Form2
Inside Form1.cmdDoIt.Click:
LOCAL loFrm
FOR EACH loFrm IN _SCREEN.FORMS
if upper(loFrm.Name)="FORM2"
* Do whatever you want with Form2 by using:
loFrm.MethodOrProperty
endif
ENDFOR
In your application object create a method called SendMessage, or as a seperate file SendMessage.prg:
LPARAMETERS pcMessage,pvData
* pvData could be any data type.
LOCAL loMsg, loFrm
loMsg = NEWOBJECT('Session')
loMsg.AddProperty('Message',pcMessage)
loMsg.AddProperty('Data',pvData)
FOR EACH loFrm IN _SCREEN.Forms
IF PEMSTATUS(loFrm,'ListenToMessages',5)
AND VARTYPE(loFrm.ListenToMessages)='L';
AND loFrm.ListenToMessages
* Do NOT put two PEMSTATUS calls on the same expression...
* It can lead to problems.
IF PEMSTATUS(loFrm,'GotMessage',5)
loFrm.GotMessage(loMsg) && Send the Message!
ENDIF
ENDIF
ENDFOR
In any forms that you want to hear the messages:
1) Create a custom property ListenToMessages;
Set it .T. if you want to get messages.
2) Create a Custom Method GotMessage with 1 parameter.
Inside that GotMessage:
LPARAMETERS poMsg
IF VARTYPE(poMsg)='O' and VARTYPE(poMsg.Message)='C'
DO CASE
CASE upper(poMsg.Message)="REFRESH ALL TREEVIEWS OF PEOPLE"
THISFORM.RefreshPeopleTreeview && or whatever is appropriate
CASE upper(poMsg.Message)="SOME OTHER MESSAGE"
THISFORM.RefreshPeopleTreeview && or whatever is appropriate
ENDCASE
ENDIF
Finally, to Send a Message:
oApp.SendMessage( "My Message", "Any value you want, or even an object!" )
* OR:
DO SendMessage WITH "My Message", "Any value you want, or even an object!"
To send multiple values, just create an object, such as:
SCATTER NAME loRec
DO SendMessage WITH "This Person is Updated", loRec