1. Berka Frenfert
  2. PowerBuilder
  3. Monday, 24 April 2023 17:30 PM UTC

I want to have one of my posted events get fired at the last in firing order.

Is there any way possible to set priority sequence number for a posted event?

Does custom Event ID somehow help to get an event posted when all other posted events are fired already?

 A parent sheet defines an event InTheEnd() and post it. When a new window inherit from parent sheet, may post many other events which i dont know how many and in what order they are posted. so I cannot tell how many events will be posted and from which events they will be posted from child window.  Is it possible to set InTheEnd() in a way it  always fires when other posted events in child window are already fired?

Accepted Answer
René Ullrich Accepted Answer Pending Moderation
  1. Tuesday, 25 April 2023 05:52 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi Berka,

there is a way you can have a event to run as last event.

Use the Yield() function to run all events in message queue before it returns to current script.

So call Yield() as first statement in the event you want to have the last one.

 

But be carefull with Yield() because it have side effects! It runs ALL kind of events in the message queue - also key strokes or mouse clicks. So for example it may be that a user presses a button to close the window. This will also processed before your last event is running. So it may be that your last event runs out of scope!

HTH,

René

Comment
  1. Berka Frenfert
  2. Tuesday, 25 April 2023 16:31 PM UTC
Hi René,

I did not know yield() had any effects on events firing order. Some time ago when i was working on how to cancel long running DB query i used yield() function in couple of events in the parent window. Those 2 places where i used yield() actually changed the events firing order which was logically not correct. That thing wasted many hours to figure out where is the problem. After i got your response i removed those yield() and every posted event finally came back into logically correct sequence. After this correction i needed to post a new InTheEnd() event from parent window and wanted it to be the last executed event in child. That was possible with Post call to InTheEnd() Inside a Posted event. for example Counstructor posted _Constructor() and further _Counstructor() posted __constructor(). This way __constructor() came at the last position in firing order.



In a parent child relation if all events are extended then all events execute in pairs for example in the following _Open is posted event from Open. __Constructor() posted from _Constructor() and _Constructor posted from Constructor() of a text control.



Sequence is as follows

----------------------

Parent:Constructor (text control)

Child:Constructor (text control)

Parent:Open

Child:Open

Parent:Activate

Child:Activate

Parent:_Constructor (text control)

Child:_Constructor (text control)

Parent:_Open

Child:_Open

Parent:__Constructor(text control)

Child:__Constructor (text control)



I used following for some app logic.

Parent:Constructor (text control)

Parent:__Constructor (text control)



I can use Child:__Constructor as well but i dont need it right now. And of course i will have to open every child window to write script which i avoided and wrote a generally common functionality in Parent:Constructor that i need when inherited window open and Parent:__Constructor after all other posted events are done.



Thanks you so much for help.



True Regard,

Berka
  1. Helpful
  1. Chris Pollach @Appeon
  2. Tuesday, 25 April 2023 19:38 PM UTC
Hi Berka;

FYI: The YIELD() command does *not* change the "order of events" (MS Message processing) in the queue. All it does is place a new Message at the End-of-the-Queue and wait for it to be posted back to the App. Thus, allowing events (messages) *already* in the queue to be processed ahead of this new message. AKA: "Hiccup Wait".

Regards ... Chris
  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 25 April 2023 12:44 PM UTC
  2. PowerBuilder
  3. # 1

You'll have to create your own event queuing system.

I would create a DataStore that has the event name, parameters, and priority level. When adding to the DataStore, post the following event:

If RowCount > 0 Then

Sort the DataStore

Get values from row 1

Delete row 1

Post the event

End If

If RowCount > 0 Then

PostEvent to self

End If

 

Comment
  1. Berka Frenfert
  2. Tuesday, 25 April 2023 15:27 PM UTC
Hi Roland,

Great idea that should work. Unfortunately my app is too old and many developers played with events the way they wanted. I am afraid to apply this technique because there gonna be a many many places to check to make sure everything is working fine. If i get any chance to create PB app from scratch i will us DataStore for events priority as you described. Thanks a lot.

True Regards,

Berka
  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 24 April 2023 19:04 PM UTC
  2. PowerBuilder
  3. # 2

I'm pretty sure they will be executed in the order they are posted. They go into a queue - first in, first out.

Comment
  1. Chris Pollach @Appeon
  2. Monday, 24 April 2023 20:19 PM UTC
Hi Roland .... You are correct (via the O/S's message queue)! ;-)
  1. Helpful
  1. Berka Frenfert
  2. Tuesday, 25 April 2023 05:27 AM UTC
That is true but FIFO does not solve my problem because i can target my very first PostEvent but later posted all events are unknown. I want to have just one such event that if posted should always be the last one. In fact, FIFO or LIFO is not important for me. How cab I post an event in parent so that the event is fired after all the other posted events in child.

Please suggest something. Thank you.

True regards,

Berka
  1. Helpful
There are no comments made yet.
Berka Frenfert Accepted Answer Pending Moderation
  1. Monday, 24 April 2023 18:38 PM UTC
  2. PowerBuilder
  3. # 3

 ChatGPT responded as following:

tongue-out

I apologize for the confusion in my previous response. You are correct that there is no SetEventPriority() function in PowerBuilder, and the syntax I provided for PostEvent() was incorrect. Here is the correct syntax:

To set the priority level of a user-defined event, you need to declare the event as a global variable in the application object or as a global structure in a global function or non-visual object. You can then use the PostEvent() function to post the event with a priority level.

For example, let's say you have defined a user-defined event called ue_myevent with a priority level of 5:

 
global event ue_myevent (integer priority = 5)

To post this event with a priority level of 5, you can use the PostEvent() function in the following way:

 
PostEvent(this, ue_myevent, 5)

In this example, this refers to the object that is posting the event, ue_myevent is the name of the event you defined, and 5 is the priority level you want to assign to the event.

I hope this clears up any confusion. Let me know if you have any further questions!

 

Congratulations to the Appeon support team their jobs are secure for sure.

 

laughing

Comment
  1. Chris Pollach @Appeon
  2. Monday, 24 April 2023 20:18 PM UTC
Hi Berka;

FYI: That's all wrong.. looks like some old remnant of a PB 3/4 syntax.

Newer PostEvent syntax would be ...

THIS.PostEvent ( "ue_myevent", {wordparm, longparm}

However, there is (and never was) any such thing as a priority level argument!!!

So basically, they gave you bad advice on that aspect. HTH

Regards .... Chris

  1. Helpful 1
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.