[SOLVED] nestedprocvars in ObjFPC mode? lazarus / 64-FPC development ---------------------------------------------------------------------- Key-Real · 2022-03-20 16:52 This works only in delphi mode. 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 delphi}{$modeswitch nestedprocvars}unit test;interfacetype    TtuiProc = procedure; procedure itemIteration(ButtonProc:TtuiProc;TextfieldProc:TtuiProc); function updateBox:boolean; implementation function updateBox:boolean;     procedure updateButtonProc;    begin    end;     procedure updateTextfieldProc;    begin    end; begin itemIteration(@updateButto nProc,@updateTextfieldProc);end;   procedure itemIteration(ButtonProc: TtuiProc;TextfieldProc:TtuiProc);begin ButtonProc; TextfieldProc;end;  beginend.  I need this feature in objfpc mode. Is it a good idea to include my suggestion this in a next version of fpc? ---------------------------------------------------------------------- Thaddy · 2022-03-20 16:54 No, it is already fully supported. Also in mode objfpc. So where's the problem exactly? And what does the compiler say? (Let me guess: ItemIteration has the wrong Params for mode objfpc compared to mode delphi) ---------------------------------------------------------------------- Key-Real · 2022-03-20 17:10 If I change the code to {$mode objfpc} The compiler say: Free Pascal Compiler version 3.3.1 [2022/03/12] for aarch64 Copyright (c) 1993-2021 by Florian Klaempfl and others Target OS: Darwin for AArch64 Compiling test.pas test.pas(27,54) Error: Incompatible type for arg no. 2: Got "", expected "" test.pas(40,4) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted ---------------------------------------------------------------------- Jonas Maebe · 2022-03-20 17:27 In Delphi mode, like in Delphi, @proc evaluates to an untyped pointer. In ObjFPC mode, @proc is the same as "proc" in Delphi mode: it evaluates to a procvar type with the signature of the passed proc. To change that into an untyped pointer in ObjFPC mode, you have to add a pointer() typecast. However, this completely eliminates type checking, which is a bad idea. The reason is that this only works in your program if updateButtonProc and updateTextfieldProc do not access local variables or parameters from updateBox. If they do, you have to change the declaration of TtuiProc to "TtuiProc = procedure is nested;". Even when they don't to this, it's better to use this correct type so you don't need the @-hack in Delphi mode to get rid of type checking, nor the pointer() hack in ObjFPC mode. ---------------------------------------------------------------------- Key-Real · 2022-03-20 18:03 Thx, now ist works! Var myProc = Procedure is Nested; Done the Job.