1. Michael Connell
  2. PowerBuilder
  3. Tuesday, 28 March 2023 14:03 PM UTC

Hi Guys,

Is it possible to trigger both the ButtonClicked and the Clicked DataWindow events when clicking a button in a DW control?

On a window I have a DataWindow control containing a button.

The button's properties are as follows:

SuppressEventProcessing = No

Action = UserDefined

I've coded both the Clicked and ButtonClicked events for the DW control, but only the Clicked event seems to fire.

From the documentation, I get the impression that it should be possible to trigger both these events:

"If Suppress Event Processing is off, the Clicked event and the ButtonClicked event are fired"

But I can't seem to get both events to fire.

What might I be doing wrong?

Regards,

Michael Connell

Michael Connell Accepted Answer Pending Moderation
  1. Tuesday, 11 April 2023 07:42 AM UTC
  2. PowerBuilder
  3. # 1

Guys,

I have some more information regarding this topic.

It seems the problem occurs only when tracing the application, and then only when there is a breakpoint in the Clicked event. Hitting this breakpoint seems to prevent the ButtonClicked event from firing.

 

Tracing itself does not appear to be a problem. When tracing with a breakpoint in the ButtonClicked event, both the Clicked and ButtonClicked events fire.

The same is true when tracing with disabled breakpoints.

When running the application, either from the IDE or from an executable, both events fire.

 

Note that I am using PowerBuilder 2021, build 1509.

I hope this clears things up a little.

Regards,

Michael.

Comment
  1. Kai Zhao @Appeon
  2. Wednesday, 12 April 2023 00:29 AM UTC
The breakpoint like a message box requires a response, so it block the ButtonClicked event too?
  1. Helpful
  1. Michael Connell
  2. Wednesday, 12 April 2023 12:20 PM UTC
Kai,

Yes, it would appear so.

Michael.
  1. Helpful
There are no comments made yet.
Michael Connell Accepted Answer Pending Moderation
  1. Thursday, 30 March 2023 08:29 AM UTC
  2. PowerBuilder
  3. # 2

John, Chris and Miguel,

Thanks for all your input.

I think Miguel hit the nail on the head when he asked what version we are using, which is 2021 build 1509.

This most likely explains the misleading documentation and the results I am seeing.

Until such time as we upgrade to 2022, I'll use John's and Chris's work-around and post the ButtoncClicked event from the Clicked event.

Thanks once again for all your help.

Regards,

Michael.

 

Comment
  1. Michael Connell
  2. Thursday, 30 March 2023 10:40 AM UTC
Kai, thanks for the tip. However, I wasn't using MessageBox at all during testing, but was tracing execution. The breakpoint in the Clicked event was being hit, but not the breakpoint in the ButtonClicked event. The only way to trigger ButtonClicked when clicking the button in the DW control was to remove all code from the clicked event.
  1. Helpful
  1. Miguel Leeuwe
  2. Thursday, 30 March 2023 11:25 AM UTC
Hi Michael, if this is happening in PB2021, then it might be a regression bug, because I believe it was no longer happening in 2019 ... But of course I'm not sure, I'd have to write a test to be sure.
  1. Helpful
  1. Miguel Leeuwe
  2. Thursday, 30 March 2023 11:32 AM UTC
Also, I think that the one who wrote the buttonclicking and buttonclicked events, maybe could have done a better job. To me it makes no sense that the clicked is fired before the buttonclicking, as an example.
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 29 March 2023 13:52 PM UTC
  2. PowerBuilder
  3. # 3

Yesterday I was about to ask you which version of PB you are using. There was indeed this buggy behavior some time ago of one of the two events not firing when you had code in both.

My recommendation is to take all of your code from the buttonClicked to your clicked event.

In latest versions the problem seems to be solved, but not a 100% sure.

regards.

Comment
There are no comments made yet.
Michael Connell Accepted Answer Pending Moderation
  1. Wednesday, 29 March 2023 13:35 PM UTC
  2. PowerBuilder
  3. # 4

John / Chris,

Thanks for your responses. Yes, I have considered posting / triggering these events to solve my particular problem.

But I still have problems understanding how these events work.

It seems that if I have any code in the Clicked event (even just comments) the Clicked event fires, but the ButtonClicked event does not. Even when clicking a button control in the DW.

If I remove the code in the Clicked event, then the ButtonClicked event fires, but naturally enough, only when clicking a button in the DW.

However, as I mentioned in my original post, the documentation states: "If Suppress Event Processing is off, the Clicked event and the ButtonClicked event are fired". (My italics).

My testing seems to indicate that this is not actually the case, and that the Clicked event somehow overrides the ButtonClicked event.

Is there something here that I'm not understanding?

Regards,

Michael.

Comment
  1. John Fauss
  2. Thursday, 30 March 2023 02:34 AM UTC
If any event's script is not empty (even if all it contains is a comment), PB will execute the script.

The PB Help topic for SuppressEventProcessing property in PB 2022 describes the property this way "Whether the ButtonClicked or ButtonClicking event is fired for this particular button. So when this property is enabled, PB will not fire either of these two events, and that's what you are experiencing. I'm not sure where the documentation you've referred resides, but I agree it is either incorrect or misleading.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 29 March 2023 01:20 AM UTC
  2. PowerBuilder
  3. # 5

Hi, Michael -

Would it be feasible/acceptable to explicitly post the DW's ButtonClicked event from the Clicked event, if the dwo argument in the Clicked event (the clicked DWObject) references the Button DWObject?

Best regards, John

Comment
  1. John Fauss
  2. Thursday, 30 March 2023 02:37 AM UTC
FYI - I tested this scenario, and it works well. The ButtonClicked event fires when explicitly triggered or posted from the DW's Clicked event, regardless of the SuppressEventProcessing setting.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 28 March 2023 21:24 PM UTC
  2. PowerBuilder
  3. # 6

Hi Michael ;

  Have you tried Posting those events instead of triggering in order to not disturb the natural order of PowerScript execution?

Regards ... Chris

Comment
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.