powerbuilder triggerevent example

Lets suppose that we have a window with two datawindow in it dw_1, dw_2 and two push buttons pb_1 pb_2.

pb_2 clicked event contains the following code
x1 = 1
dw_2.show()
dw_2.setfocus()


pb_1 clicked event contains the following code
x1 = 2
pb_2.triggerevent(clicked!)
messagebox("hi", string(x1))

my problem is that when i press pb1 button  pb2 clicked event is fired (x1 = 1) but dw_2 is receiving focus after the execution of messagebox command and not before it as i expected. Can i bypass this problem somehow (possibly with another technique)? i know than i can use a
responsed window containing dw_2 instead. i am interested in another solution if possible.


basilhs_sAsked:
Who is Participating?
 
MarkPTXCommented:
Here's a trick we use to delay a messagebox. Create a new function in you n_appmanager:

of_postmessage return long  with 2 arguments:
string as_title
string as_msg

long ll_rc

ll_rc = MessageBox(as_title, as_msg)

Return ll_rc


Then in your code use this:

gnv_app.Post of_PostMessage('hi', String(x1))

Since you are posting this, there is no way to capture the return from the function so you cannot use this trick if you need to know which button they clicked but for OK messages, this works nicely.


You can also write a similar function if you are using the MESSAGES table and the inv_error.of_Message function. If you are, I can send you that function as well.
0
 
sandeep_patelCommented:
I am sure your datawindow is getting focus first, but you are displaying message immediately after that and hence focus is now on message box and once you close message box, it goes back to datawindow.

Write messagebox('','focus') in getfocus event of dw_2 and you will see that it's getting a focus before or not.

Regards,
Sandeep
0
 
basilhs_sAuthor Commented:
i used the messagebox to show that dw_2 receive the focus after the completion of pb1 clicked event.
0
 
basilhs_sAuthor Commented:
thanks very much
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.