Something is wrong with this code, but I can't decide what it is lazarus / 64-FPC development ---------------------------------------------------------------------- ALLIGATOR · 2025-05-17 08:28 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 program app;{$modeswitch anonymousfunctions} type  TMyProc = procedure (value: NativeInt); procedure Test(const anonproc);begin  TMyProc(@anonproc)(33);end; procedure Run;begin  Test(procedure (value: NativeInt)       begin         WriteLn('Anon value = ', value);       end);end; begin  Run;  ReadLn;end. Output (x86_64) (can be a random value, on Linux a different value): Code: [Select]2 My options: It should be fixed that in this case arguments are not shifted by 1 as they are now. RCX (x86_64 Windows) is occupied by an implicit argumentIt is necessary to pass not a pointer to the code, but form a full reference to / $CapturerClass_*Forbid to pass such parameters to such type (D12.1CE does this, but I don't like this idea very much, because possible flexibility is lost) ---------------------------------------------------------------------- Fibonacci · 2025-05-17 11:01 I vote for option 1, but will be fixed with option 3 (easiest), as was done with @ - I was using that syntax @PascalDragon: Made sure that @ is now completely forbidden ---------------------------------------------------------------------- ALLIGATOR · 2025-05-17 11:14 Although... for some reason I didn't think of it right away. but this code is fixed like this, so maybe it's not a problem at all? ) 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 program app;{$modeswitch anonymousfunctions} type  TMyProc = procedure (value: NativeInt) of object; procedure Test(const anonproc);var  m: TMethod;begin  m.Code:=@anonproc;  TMyProc(m)(33);end; procedure Run;begin  Test(procedure (value: NativeInt)       begin         WriteLn('Anon value = ', value);       end);end; begin  Run;  ReadLn;end. ---------------------------------------------------------------------- ALLIGATOR · 2025-05-17 11:28 Quote from: Fibonacci on May 17, 2025, 01:01:25 pm@ - I was using that syntax ... Made sure that @ is now completely forbidden[/url][/i] I'm a little confused about your message You can do that: 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 program app;{$modeswitch anonymousfunctions} type  TProc = procedure(value: NativeInt); procedure Test2(anonproc: TProc);begin  anonproc(55);end; begin  Test2(procedure(value: NativeInt)        begin          WriteLn(value);        end);  ReadLn;end. Is there anything wrong with that option? ---------------------------------------------------------------------- Fibonacci · 2025-05-17 11:43 I had a specific use case where a procedure accepted few different anon functions (different arg types, arg count) which were used to set them as callbacks, it worked fine. Something like 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 blahblah('something', @(procedure(a: string; b: integer) begin  // ...end),  ['xaxa', 1337]); ---------------------------------------------------------------------- ALLIGATOR · 2025-05-17 12:35 In general, I originally wanted to do this kind of “convert” an anonymous function into a method And the fact that now the first argument is passed to RDX is even to my advantage, so I withdraw my wishes I'm happy with everything now, but there is room for discussion, of course 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 program app;{$mode objfpc}{$modeswitch anonymousfunctions} uses Classes; generic function AnonymToMethod(AObj: Tobject; const AnonProc): T;begin  TMethod(Result).Code:=@AnonProc;  TMethod(Result).Data:=AObj;end; var  SL: TStringList; begin  SL := TStringList.Create;  SL.OnChange:=specialize AnonymToMethod(SL,    procedure (Sender: TObject)    begin      WriteLn((Sender as TStringList).Count);    end);   SL.Add('1');  SL.Add('2');  SL.Add('3');   ReadLn;end. ---------------------------------------------------------------------- Fibonacci · 2025-05-25 13:11 Can someone check if this is allowed in Delphi? 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 {$modeswitch anonymousfunctions}var  p: pointer;begin  p := @(procedure begin    writeln('hello');  end);  tprocedure(p);  readln;end. This is now forbidden (illegal expression) in FPC, but why? The problem is that if I use "function references" modeswitch, TCapturer gets into action and my mini-exe, instead of being 6 KB, now becomes 12 KB! ---------------------------------------------------------------------- ALLIGATOR · 2025-05-25 13:47 In D12.1CE it works: 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 program app; type  TProcedure = reference to procedure; var  p: pointer; begin  p := @(procedure begin    WriteLn('hello');  end);  TProcedure(p)();  ReadLn;end. ---------------------------------------------------------------------- ALLIGATOR · 2025-05-25 13:50 And this doesn't work in FPC[git main]: 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 program app;{$mode delphi}{$modeswitch anonymousfunctions}{$modeswitch functionreferences} type  TProcedure = reference to procedure; var  p: pointer; begin  p := @(procedure begin    WriteLn('hello');  end);  TProcedure(p)();  ReadLn;end. ---------------------------------------------------------------------- Fibonacci · 2025-05-25 13:55 Without the reference works too? 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 program app; type  TProcedure = procedure; var  p: pointer; begin  p := @(procedure begin    WriteLn('hello');  end);  TProcedure(p)();  ReadLn;end. ---------------------------------------------------------------------- ALLIGATOR · 2025-05-25 17:00 compiles but doesn't work ---------------------------------------------------------------------- Fibonacci · 2025-05-25 17:01 Ok, thanks for testing ---------------------------------------------------------------------- Thaddy · 2025-05-26 08:22 TProcedure is already declared in system, so do not redeclare it as its reference..... https://www.freepascal.org/docs-html/rtl/system/tprocedure.html Maybe the code will work if you declare the reference as TProcedureRef instead of Tprocedure? Can' t test now. But it is the case in both Delphi 12.1 and FPC. ---------------------------------------------------------------------- ALLIGATOR · 2025-05-26 09:20 . ---------------------------------------------------------------------- 440bx · 2025-05-26 09:43 @ALLIGATOR, if I may ask, what font are you using ? Thank you in advance. ---------------------------------------------------------------------- paweld · 2025-05-26 10:04 @440bx: Looks like Consolas. Some fonts for comparison: https://forum. lazarus.freepascal.org/index.php/topic,70446.msg549165.html#msg549165 ---------------------------------------------------------------------- ALLIGATOR · 2025-05-26 10:11 Never thought about it, the default font ---------------------------------------------------------------------- Thaddy · 2025-05-26 10:46 What I meant is: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 {$mode objfpc}{$modeswitch functionreferences}type  TProcedureRef = reference to Procedure;  procedure hello;  begin    writeln('hello');  end;;var  p:TProcedureRef;begin  p:=@hello;// maybe mode delphi accepts: p:=hello()  p();end.Untested. ---------------------------------------------------------------------- 440bx · 2025-05-26 10:55 Thank you @paweld and Thank you ALLIGATOR. That font looked quite readable, for that reason I wanted to know which one it was. ---------------------------------------------------------------------- Thaddy · 2025-05-27 08:21 @ALLIGATOR Answer to original question: 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 program project1;{$ifdef fpc}{$mode delphi}{$modeswitch anonymousfunctions}{$modeswitch functionreferences}{$endif}type  TMyProc = reference to procedure (value: NativeInt); // <<------reference---- procedure Test(const anonproc:TMyProc);begin  anonproc(33);end; procedure Run;begin  Test(procedure (value: NativeInt)       begin         WriteLn('Anon value = ', value);       end);end; begin  Run;  ReadLn;end. Small change, but that is what I meant: it should be a reference. Btw: highly contrived code you wanted, but it works now. This is actually another example of combining anonymous methods and function references similar to what I gave last week.