Feature Requst: TThread.TerminatedSet lazarus / 62-General ---------------------------------------------------------------------- Zaher · 2020-07-18 16:19 Not just for compatible with Delphi, I need a method to override it, when someone/code called thread.Terminate In Delphi it is TerminatedSet I will report it in the bug tracker. if it acceptable. EDIT Fixed to TerminatedSet ---------------------------------------------------------------------- jamie · 2020-07-18 16:29 What's the problem ? I don't fully understand here. Using the Terminate method it sets the Terminated property to true but that's it. From there your code in the thread should be monitoring that property at all times during its loop and if is set then it just exits.  I don't see a difference ? EDIT:   Maybe you are looking for an early warning so that other threads can test if the Terminate has been called but not yet satisfied ? Is that it ? ---------------------------------------------------------------------- jamie · 2020-07-18 16:48 Currently you need to build your thread based from a TThread class now so that means you can have in class a field that is set via the Terminate call to reflect this.. I suppose it would be a good idea to report this as a wish ---------------------------------------------------------------------- Zaher · 2020-07-18 17:10 Ah ok, I always need Terminate as virtual method to override it when called I stop actions, Like: Socket reading and waiting, when I want to stop reading, I close the handle of socket, that stop reading then exit from read. Also if I am in waiting event etc etc, I setEvent to exit from waiting, when trigger terminate, I need to call my own method Stop after or before it to make this action, I need it offical, if I call Terminate, i want to do that things. that one of my real project needs it https://github.com/parmaja/minilib/blob/master/socket/source/mnIRCClie nts.pas#L1935 https://github.com/parmaja/minilib/blob/master/socket/source/mnIRCClie nts.pas#L1849 https://github.com/parmaja/minilib/blob/master/socket/source/mnIRCClie nts.pas#L1599 make Terminate as virtual is good for me, or add TerminateSet as in Delphi that better just to make my code compiled in both FPC and Delphi ---------------------------------------------------------------------- Zaher · 2020-07-18 17:21 Reported https://bugs.freepascal.org/view.php?id=37388 ---------------------------------------------------------------------- rvk · 2020-07-18 17:29 Quote from: Zaher on July 18, 2020, 07:10:15 pmmake Terminate as virtual is good for me, or add TerminateSet as in Delphi that better just to make my code compiled in both FPC and Delphi TerminateSet??? Do you mean TThread.TerminatedSet? http://docwiki.embarcadero.com/Libraries/Rio/en/System.Classes.TThread .TerminatedSet Does Embarcadero have any documentation (other than that empty page)? https://stackoverflow.com/questions/33962710/implement-override-for- thread-terminate-method ---------------------------------------------------------------------- Thaddy · 2020-07-18 19:26 Terminate(XXX) without waitfor is useless. ---------------------------------------------------------------------- Zaher · 2020-07-18 21:56 Quote from: rvk on July 18, 2020, 07:29:09 pm TerminateSet??? Do you mean TThread.TerminatedSet? http://docwiki.embarcadero.com/Libraries/Rio/en/System.Classes.TThread .TerminatedSet Yes , I think I need a glasses ---------------------------------------------------------------------- jamie · 2020-07-19 02:02 Yes, I hope they put that feature in. That way other threads can check to see if it was set for a terminate state but not depend on it just because it is still running..  if Mythread.TerminatedSet then Don't_Bother_To_dependOnThread_Being_valid; What they should have done instead of using "CheckTerminated" would be to CheckRunningState:Integer;    0  := Dead;    1  := Running;    -1 :=Shutting down;  or use a Set type  TThreadRuningState = (tsStopped, TsRunning, tsShuttingDown); etc have fun.. ---------------------------------------------------------------------- rvk · 2020-07-19 03:41 Quote from: jamie on July 19, 2020, 04:02:34 amYes, I hope they put that feature in. That way other threads can check to see if it was set for a terminate state but not depend on it just because it is still running.. if Mythread.TerminatedSet then Don't_Bother_To_dependOnThread_Being_valid; TThread.TerminatedSet is not a function in Delphi. Look at http://docwiki.embarcadero.com/Libraries/Rio/en/System.Classes .TThread.TerminatedSet So you can't use it like you showed/wanted. For that you have TThread.Terminated and TThread.Finished. ---------------------------------------------------------------------- Thaddy · 2020-07-19 08:07 Quote from: rvk on July 19, 2020, 05:41:35 amFor that you have TThread.Terminated and TThread.Finished. And Waitfor Anyway looks like it is fixed. https://bugs.freepascal.org/view.php?id=37388 ---------------------------------------------------------------------- coliv_aja · 2020-09-15 01:48 I had been masking TThread.Terminate this whole time. because it's not s virtual. And FTerminated is a private var. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TMyThread.Terminate;begin   inherited Terminate; // to set FTerminated   socket.abort;end;  But I'm glad there's a virtual method TThread.TerminatedSet to override.