[Solved] Declare a procedure as a parameter of another procedure. lazarus / 21-General ---------------------------------------------------------------------- pebe · 2022-03-31 06:10 Hello. I wanted to pass a callback (procedure) parameter to a procedure I used the following code: in unit interface 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 type   TUpdateProcedure = procedure(currentRow:integer); function LoadCSV2DB(FileStream:TFileStream; Query:TSQLQuery; Tran:TSQLTransaction;                           Update:TUpdateProcedure; ADelimiter:Char=','):Boolean;  in Form method 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 TDBForm.actCSVImportExecute(Sender:TObject);   procedure UpdateETA(currentRow:integer);  begin    {code of callback function}  end; begin  {somewere in method}  if Not LoadCSV2DB(FileStream,Query,Tran,@UpdateETA) then  {...}end; However, the compilation attempt ends with an error: Error: (4025) Incompatible type for arg no. 4: Got "
", expected "" What am I doing wrong? ---------------------------------------------------------------------- Zvoni · 2022-03-31 06:36 Quote from: pebe on March 31, 2022, 08:10:46 am Error: (4025) Incompatible type for arg no. 4: Got "
", expected "" What am I doing wrong? ---------------------------------------------------------------------- Red_prig · 2022-03-31 06:41 In this case, you have one procedure nested inside another, for this you need a separate type of callback, read here https://www.freepascal.org/docs-html/ref/refse17.html ---------------------------------------------------------------------- howardpc · 2022-03-31 06:49 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 nestedprocvars} type   TUpdateProcedure = procedure(currentRow: Integer) is nested;... ---------------------------------------------------------------------- pebe · 2022-03-31 18:43 Thanks for the explanation. I didn't think such a declaration was differentiated by FP. I don't go into why, however now I know how to "look" at procedural variables. Thanks again and Regards. ---------------------------------------------------------------------- PascalDragon · 2022-04-01 13:37 Quote from: pebe on March 31, 2022, 08:43:19 pmI don't go into why, however now I know how to "look" at procedural variables. Nested functions have an additional, hidden parameter that contains the frame pointer of the parent (where all the variables from the parent scope are), just like an instance or class method contains a hidden Self parameter. A normal procedure variable can not hold this as it's only a single pointer. Thus is nested (and of object for instance/class methods) exists as a variable of that type in fact contains of two pointers.