{"id":613,"date":"2010-12-03T20:20:45","date_gmt":"2010-12-04T01:20:45","guid":{"rendered":"http:\/\/anvil-of-time.com\/wordpress\/?p=613"},"modified":"2021-03-10T18:14:31","modified_gmt":"2021-03-10T23:14:31","slug":"powerbuilder-calling-methods-on-separate-windows","status":"publish","type":"post","link":"https:\/\/anvil-of-time.com\/powerbuilder\/powerbuilder-calling-methods-on-separate-windows\/","title":{"rendered":"PowerBuilder &#8211; Calling Methods on Separate Windows"},"content":{"rendered":"<p>If you need to trigger and event or call a function on another window within an application, here are two solutions.<\/p>\n<p>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 &#8216;of_getsheetsbyclass&#8217;.  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.<\/p>\n<pre name=\"code\" class=\"VB\">\/\/ int wf_getsheetsbyclass(ref aw_windowarray[], as_classname)\ninteger li_counter\nwindow\tlw_sheet\n\n\/\/ Get all sheets of classname\nlw_sheet = this.GetFirstSheet ()\nif IsValid (lw_sheet) then\n   do\n      if ClassName (lw_sheet) = as_classname then\n         li_counter++\n         aw_windowarray[li_counter] = lw_sheet\n      end if\n      lw_sheet = this.GetNextSheet (lw_sheet)\n   loop until IsNull(lw_sheet) Or not IsValid (lw_sheet)\nend if\n\nreturn li_counter<\/pre>\n<p>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.<\/p>\n<pre name=\"code\" class=\"VB\">integer\tli_return\nwindow\tlw_opensheets[]\n\/\/ using hard coded value but could just as easily be a string parameter\nli_return = this.wf_GetSheetsByClass(lw_opensheets,&#039;w_inv_action_list&#039;)\n\nIF li_return &gt; 0 THEN\n\t\/\/ 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.\n\t\/\/ in this instance, trigger it on the first sheet in my lw_opensheets array\n   \/\/ trigger event on sheet and send it a string parameter\n   lw_opensheets[1].event dynamic ue_nextreq(as_parms)\nELSE\n   \/\/open the sheet then trigger?\nEND IF<\/pre>\n<p>So in Sheet A you call\/trigger the method on Sheet B like this:<\/p>\n<pre name=\"code\" class=\"VB\"> w_frame.event dynamic ue_nextreq(ls_parm)<\/pre>\n<p>Where &#8216;w_frame&#8217; is the name of your frame window.<\/p>\n<p>If you are not using an MDI application the approach is a bit more straightforward.  This code is in the CALLING window.<\/p>\n<pre name=\"code\" class=\"VB\">IF not IsValid(w_window_b) THEN   \n  open( w_window_b)\n  post close( w_window_b) \/\/ only if it wasn&#039;t open already\nend if\n\nw_window_b.event ue_compute()<\/pre>\n<p>If you don&#8217;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.<\/p>\n<p>If the window is as response window, at the moment you execute the &#8216;open()&#8217; your code will wait to execute until it closes. If you don&#8217;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 &#8216;dummy&#8217; 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.<\/p>\n<p>Your code would then look like:<\/p>\n<pre name=\"code\" class=\"VB\">open(w_mdiframe_test) \/\/ open the dummy frame\nopensheet( w_response_test,w_mdiframe_test)\npost close( w_response_test) \/\/ only if it wasn&#039;t open already\npost close(w_mdiframe_test) \/\/ close the dummy mdi frame\n\nw_response_test.event ue_callme()<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8216;of_getsheetsbyclass&#8217;. You call it and&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,10],"tags":[27,12,16],"_links":{"self":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/613"}],"collection":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/comments?post=613"}],"version-history":[{"count":6,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/613\/revisions"}],"predecessor-version":[{"id":1892,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/613\/revisions\/1892"}],"wp:attachment":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/media?parent=613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/categories?post=613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/tags?post=613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}