Powerbuilder – Calling Methods on Separate Windows
If you need to trigger and event or call a function on another window within an application, here are two solutions.
In you have an MDI application you need to get a reference to the sheet. The PFC has a method to get the sheets of a certain class called ‘of_getsheetsbyclass’. You call it and pass in a window array and the classname (window name) you are looking for and it populates the window array and returns the number of sheets of that particular class. This can be put on your frame directly fairly easily. Define a function on the MDI Frame window which takes a window array parameter by reference and a string. The function returns an integer.
// int wf_getsheetsbyclass(ref aw_windowarray, as_classname) integer li_counter window lw_sheet // Get all sheets of classname lw_sheet = this.GetFirstSheet () if IsValid (lw_sheet) then do if ClassName (lw_sheet) = as_classname then li_counter++ aw_windowarray[li_counter] = lw_sheet end if lw_sheet = this.GetNextSheet (lw_sheet) loop until IsNull(lw_sheet) Or not IsValid (lw_sheet) end if return li_counter
Create an event on the Frame to call the function. This event gets triggered by the sheet FROM which you wish to call the other sheet. Add parameters as needed.
integer li_return window lw_opensheets // using hard coded value but could just as easily be a string parameter li_return = this.wf_GetSheetsByClass(lw_opensheets,'w_inv_action_list') IF li_return > 0 THEN // if multiple versions of the same sheet are open, you have may wish to do extra stuff to trigger the event on the correct one. // in this instance, trigger it on the first sheet in my lw_opensheets array // trigger event on sheet and send it a string parameter lw_opensheets.event dynamic ue_nextreq(as_parms) ELSE //open the sheet then trigger? END IF
So in Sheet A you call/trigger the method on Sheet B like this:
w_frame.event dynamic ue_nextreq(ls_parm)
Where ‘w_frame’ is the name of your frame window.
If you are not using an MDI application the approach is a bit more straightforward. This code is in the CALLING window.
IF not IsValid(w_window_b) THEN open( w_window_b) post close( w_window_b) // only if it wasn't open already end if w_window_b.event ue_compute()
If you don’t want the flicker of the window opening and closing you could send it a parameter in an Openwithparm call (instead of Open) which you read in the open event of the window and then set the x,y coordinates of the window to -5000 or something.
If the window is as response window, at the moment you execute the ‘open()’ your code will wait to execute until it closes. If you don’t want to change its type, you can also do an OpenSheet(). That will make the called window behave like a sheet, even though the type is response. With this approach you will also need to create a ‘dummy’ MDI frame which you open first then use in the opensheet call. Interestingly the Powerbuilder help explicitly states NOT to open a response window with the opensheet command.
Your code would then look like:
open(w_mdiframe_test) // open the dummy frame opensheet( w_response_test,w_mdiframe_test) post close( w_response_test) // only if it wasn't open already post close(w_mdiframe_test) // close the dummy mdi frame w_response_test.event ue_callme()You might also be interested in