Anonymous methods/Closures lazarus / 64-FPC development ---------------------------------------------------------------------- lazycat2 · 2022-07-04 14:06 As FreePascal doesn't support anonymous methods/closures, what is the best way to write code like I posted below in FreePascal? 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 DoSomethingInBackgroundThread;var  L1, L2: Integer;begin  TThread.Synchronize(procedure  begin    DoSomethingElse(L1, L2);  end);end;  The obvious way I see is to use a TThread class, converting L1 and L2 to fields - but that means a lot of typing... ---------------------------------------------------------------------- lazycat2 · 2022-07-04 14:16 Sorry posted in the wrong section, this was intended for General. ---------------------------------------------------------------------- marcov · 2022-07-04 14:17 It is exactly right.  Anonymous methods are only supported in the development version trunk/main ---------------------------------------------------------------------- marcov · 2022-07-04 14:18 Quote from: marcov on July 04, 2022, 04:17:36 pmIt is exactly right.  Anonymous methods are only supported in the development version trunk/main Typical solution is a queue to hold L1, l2 tuples, and then .synchronize a method that drains the queue. ---------------------------------------------------------------------- lazycat2 · 2022-07-07 15:53 Quote from: marcov on July 04, 2022, 04:18:37 pmTypical solution is a queue to hold L1, l2 tuples, and then .synchronize a method that drains the queue. Interesting. Is this an existing feature in FPC/Lazarus? ---------------------------------------------------------------------- Leledumbo · 2022-07-14 06:04 Quote from: marcov on July 04, 2022, 04:18:37 pmQuote from: marcov on July 04, 2022, 04:17:36 pmIt is exactly right.  Anonymous methods are only supported in the development version trunk/main Typical solution is a queue to hold L1, l2 tuples, and then .synchronize a method that drains the queue. Why not simply put L1 and L2 into unit level? ---------------------------------------------------------------------- PascalDragon · 2022-07-14 06:44 Quote from: lazycat2 on July 07, 2022, 05:53:28 pmQuote from: marcov on July 04, 2022, 04:18:37 pmTypical solution is a queue to hold L1, l2 tuples, and then .synchronize a method that drains the queue. Interesting. Is this an existing feature in FPC/Lazarus? Not in its totality, but the necessary building blocks are there. Quote from: Leledumbo on July 14, 2022, 08:04:29 amQuote from: marcov on July 04, 2022, 04:18:37 pmQuote from: marcov on July 04, 2022, 04:17:36 pmIt is exactly right.  Anonymous methods are only supported in the development version trunk/main Typical solution is a queue to hold L1, l2 tuples, and then .synchronize a method that drains the queue. Why not simply put L1 and L2 into unit level? What if you have multiple threads or multiple invocations of DoSomethingInBackgroundThread? In context of threading global variables are nearly always the wrong answer. ---------------------------------------------------------------------- Leledumbo · 2022-07-14 07:35 Quote from: PascalDragon on July 14, 2022, 08:44:41 amWhat if you have multiple threads or multiple invocations of DoSomethingInBackgroundThread? In context of threading global variables are nearly always the wrong answer. Ah, OK. That makes sense. ---------------------------------------------------------------------- marcov · 2022-07-14 10:45 Quote from: PascalDragon on July 14, 2022, 08:44:41 amQuote from: Leledumbo on July 14, 2022, 08:04:29 amWhy not simply put L1 and L2 into unit level? What if you have multiple threads or multiple invocations of DoSomethingInBackgroundThread? In context of threading global variables are nearly always the wrong answer. Or in my case, I had slow UI components like TChart in applications that had 3 cameras x 40fps.