DavidJr. 1 Posted April 26, 2022 (edited) Hi, I am trying to understand TSimpleEvent (or TEvent) and complete documentation with examples doesn't seem to be so easy to find. I suspect that it can be used as a trigger more effectively than a boolean, but I am not so sure without a better understanding. I would like to create a one time trigger that is set as an event so a procedure can execute. The procedure unset it and set another Event to allow for a waitfor() like procedure to wait for the procedure to finish work. IS my understanding of a TSImpleEvent in that it can serve as a trigger correct? Also how is it turned on and off? I got the idea from Bechhoff's TwinCAT3 environment where there is a Trigger object that once its read its automatically turned off so to NOT allow a method called by the trigger to be called more than once. Thanks. Edited April 26, 2022 by DavidJr. Share this post Link to post
Remy Lebeau 1436 Posted April 26, 2022 1 hour ago, DavidJr. said: I am trying to understand TSimpleEvent (or TEvent) and complete documentation with examples doesn't seem to be so easy to find. Really? https://docwiki.embarcadero.com/Libraries/en/System.SyncObjs.TSimpleEvent https://docwiki.embarcadero.com/Libraries/en/System.SyncObjs.TEvent https://docwiki.embarcadero.com/RADStudio/en/Waiting_for_a_Task_to_Be_Completed Share this post Link to post
DavidJr. 1 Posted April 26, 2022 (edited) Yes. I saw those. But I do not know from those pages the proper way to use SetEvent or ResetEvent or any properites or other methods. No example code like you would expect from TTask and the like. More specifically What is SetEvent doing vs ResetEvent? Which thread has rights to these methods? Edited April 26, 2022 by DavidJr. clarify Share this post Link to post
Remy Lebeau 1436 Posted April 26, 2022 1 hour ago, DavidJr. said: Yes. I saw those. But I do not know from those pages the proper way to use SetEvent or ResetEvent or any properites or other methods. What exactly are you so confused about? A T(Simple)Event has a state - signaled or unsignaled. You set the initial state when you create the event. You update the state with SetEvent() (signaled) and ResetEvent() (unsignaled), and use WaitFor() to test whether the event is signaled or not, optionally waiting for a period of time to see if an unsignaled event becomes signaled. Period. It is really not more complicated than that. 1 hour ago, DavidJr. said: More specifically What is SetEvent doing vs ResetEvent? What more do you want to know that the documentation is not already telling you? https://docwiki.embarcadero.com/Libraries/en/System.SyncObjs.TEvent.SetEvent Quote Turns on the signal of the event object. https://docwiki.embarcadero.com/Libraries/en/System.SyncObjs.TEvent.ResetEvent Quote Turns off the signal of the event object. https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.SyncObjs.THandleObject.WaitFor Quote Waits until this THandleObject object enters into the signaled state. 1 hour ago, DavidJr. said: Which thread has rights to these methods? All threads in your process that can access the T(Simple)Event object itself will have rights to call the event's methods. Also, if you assign a name to the event, any thread in another process can open the event by that name. Such a thread will have access to update the event's state if it requests the EVENT_MODIFY_STATE right when opening the event, and access to wait on the event's signaled state if it requests the SYNCHRONIZE right. Share this post Link to post
DavidJr. 1 Posted April 26, 2022 (edited) 7 minutes ago, Remy Lebeau said: What exactly are you so confused about? A T(Simple)Event has a state - signaled or unsignaled. You set the initial state when you create the event. You update the state with SetEvent() (signaled) and ResetEvent() (unsignaled), and use WaitFor() to test whether the event is signaled or not, optionally waiting for a period of time to see if an unsignaled event becomes signaled. Period. It is really not more complicated than that. What more do you want to know that the documentation is not already telling you? https://docwiki.embarcadero.com/Libraries/en/System.SyncObjs.TEvent.SetEvent https://docwiki.embarcadero.com/Libraries/en/System.SyncObjs.TEvent.ResetEvent https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.SyncObjs.THandleObject.WaitFor All threads in your process that can access the T(Simple)Event object itself will have rights to call the event's methods. Also, if you assign a name to the event, any thread in another process can open the event by that name. Such a thread will have access to update the event's state if it requests the EVENT_MODIFY_STATE right when opening the event, and access to wait on the event's signaled state if it requests the SYNCHRONIZE right. This is helpful. Other than this page: https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.SyncObjs.THandleObject.WaitFor , I did not see these pages until you provided links: https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.SyncObjs.TEvent.SetEvent https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.SyncObjs.TEvent.ResetEvent Thank you for the info. Edited April 26, 2022 by DavidJr. Share this post Link to post