Maybe some Delphi framework already has this functionality, but somebody may find this interesting.

Maybe some Delphi framework already has this functionality, but somebody may find this interesting.
+Truly cross-platform (Delphi 5+, FPC).
http://blog.kluug.net/2015/03/05/procedure-call-with-delay/

Comments

  1. By the way, TTimer can't be safely created in a thread other than the main thread, because it called AllocateHWnd which isn't threadsafe. Also, I was curious about freeing the object - you say (in the comments at the top of the file) to free it early to stop the timer firing, but not to free after it fired. How do you synchronise that?

    ReplyDelete
  2. David Millington I used only the TTimer and not a thread before, so this is/was not an issue.
    About the freeing: the comment is a little bit misleading. What I meant is that the object can be destroyed (e.g. automatically by destroying the owner - closing the form). It's not supposed to be destroyed manually. (But you could test if the object is still in the owner's componentlist, which is not very nice, I know.)

    ReplyDelete
  3. I updated the code, now the call object can be destroyed (via Free) even after the time limit (because the variable reference will be set to nil in the destructor).

    ReplyDelete

Post a Comment