1. Sivaprakash BKR
  2. PowerBuilder
  3. Saturday, 26 June 2021 07:07 AM UTC

Hello,

PB 2019 R3 

I'm calling one window (w_called), as an instance from another window (w_calling).  The code

in w_calling window
w_called       w_1
Opensheetwithparam (w_1, param, w_main, 0, Original!)

After processing, at closing time of w_called window, I want to trigger one event in w_calling window.  How could I call an event ?   

I tried passing the window name (w_calling) as a parameter, that's not working.   Any idea how to call an event ?

Happiness Always
BKR Sivaprakash

 

Sivaprakash BKR Accepted Answer Pending Moderation
  1. Wednesday, 30 June 2021 07:58 AM UTC
  2. PowerBuilder
  3. # 1

Thanks John and Mark

We have implemented the idea given by John and it's working.

 

Comment
There are no comments made yet.
Mark Goldsmith Accepted Answer Pending Moderation
  1. Sunday, 27 June 2021 17:19 PM UTC
  2. PowerBuilder
  3. # 2

Hi BKR Sivaprakash,

Further to John's suggestions and his follow-up reply (have a great holiday John), it's about getting the right window reference. You could also make use of the FindWindowW() API call, providing a reference/ handle to the w_calling window.

Then you could use the Send() function from the w_called window to trigger the event in question in w_calling. This would streamline your code a bit and save you from having to cycle through all of the sheets looking for the correct w_calling window. More details can be found about this approach in the Help (within the IDE and at docs.appeon.com), but let me know if you have any questions.

HTH...regards,

Mark

Comment
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Saturday, 26 June 2021 14:05 PM UTC
  2. PowerBuilder
  3. # 3

Thanks John for your detailed reply, as usual.
Yes, I need to call an event in the w_calling window from w_called window. It's bit more complicated in the sense that w_called window could be called by many a windows (w_calling, w_calling1, w_calling2 .... w_callingn).

So, my coding 

window wSheet
If IsValid(w_main) then
wSheet = w_main.GetFirstSheet()
If IsValid(wSheet) Then
If wsheet.Title = is_call_from Then
wsheet.TriggerEvent('ue_retrieve_list')
Else
Do
wSheet = w_main.GetNextSheet(wSheet)
lb_found = IsValid (wSheet)
If lb_found Then
If wsheet.Title = is_call_from Then
wsheet.TriggerEvent('ue_retrieve_list')
End If
End If
Loop While lb_found
End If
End If

Currently, we assign a Title for every window (w_calling) and we pass that title to w_called window.   That value is assigned to is_call_from and we check that value to trigger the event.

Is this the only way available ?  Or anything better could be done ?

Happiness Always
BKR Sivaprakash

 

Comment
  1. John Fauss
  2. Sunday, 27 June 2021 14:33 PM UTC
It all comes back to: You need a reference to the w_calling window. You might wish to check the ClassName() of each window returned by the GetFirstSheet / GetNextSheet functions in addition to comparing the window title, as added insurance.

What is the problem using this technique?

An alternative would be to develop your own “sheet manager” functionality, but PB does not supply this. I believe Chris’ STD framework may have one, but it would be integrated into that framework.

I’m on holiday for a week, so I may not respond quickly to responses. I encourage others in the Community to offer their ideas for your consideration.
  1. Helpful
  1. Sivaprakash BKR
  2. Tuesday, 29 June 2021 11:56 AM UTC
Thanks John, ClassName() is working fine. My (mis)understanding about ClassName() is the reason that I didn't try it earlier. Now I understood and modified my code which works great.

  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Saturday, 26 June 2021 13:36 PM UTC
  2. PowerBuilder
  3. # 4

You need a reference to the instance of the w_calling window you wish to close.

If the OpenSheetWithParm for the instance of the w_called window is being called from the w_calling window, then include a reference in the parameters structure that is passed into w_called:

params.calling_window = This
OpenSheetWithParm(w_1,param,w_main,0,Original!)

Next, in w_called, save the reference to the calling window in an instance variable:

window iw_calling   // A generic window reference is adequate unless you want to access methods or public properties specific to w_calling, in which case you would declare as:
w_calling iw_calling

Then, in the Open event of w_called:

iw_calling = params.calling_window

Finally, when you wish to close the instance of w_calling,

If IsValid(iw_calling) Then
   Close(iw_calling)
End If

If you do not or cannot pass a reference to the instance of w_calling in to the w_called window, it's a little more complicated. You can use the GetFirstSheet() and GetNextSheet() PowerScript functions to obtain a reference to all sheet windows, one at a time. See the Help topics on each for more information. Always use IsValid() to ensure the reference you obtain is valid, then check each window's class name using the ClassName() method to see if it is a window of type w_calling. Once you find it, use the Close() PowerScript command.

Note that if there can be multiple sheet windows of type w_calling open simultaneously, this technique will NOT identify the one instance that opened w_called... in which case you really need to pass the reference to w_calling in to w_called via the parameters structure.

Regards,
John

Comment
  1. Chris Pollach @Appeon
  2. Sunday, 27 June 2021 17:37 PM UTC
Hi John ... Basically, you've hit the solution nail on the head with this post! ;-)
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.