Need help about Procedure Type lazarus / 62-General ---------------------------------------------------------------------- jiaxing2 · 2020-05-13 07:44 I still not grasp Pascal's procedure type  For example: 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  MyType = function GetMyType(x: integer): integer; Do I write the function code directly in Type block above or split declaration/implementation like usual? And how the procedure type work? When I write: y: MyType does it means: 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 //pseudocodevar y: integer;y:= GetMyType(y); I'm still very confused ---------------------------------------------------------------------- Bart · 2020-05-13 09:02 Maybe something like this? (untested code) 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  TMyFunc = function(x: integer): integer; function foo(x: integer):integer;begin  result := x*x;end; function bar(x: integer): integer;begin  result := -x;end; var  MyFunc: TMyFunc;begin  ...  if SomeCondition then    MyFunc := @foo  else    MyFunc := @bar;  writeln('MyFunc(2) = ',MyFunc(2));end. Bart ---------------------------------------------------------------------- Thaddy · 2020-05-13 09:58 Bart, For mode objfpc this should work. In mode delphi the @'s are not necessary and should also work. ---------------------------------------------------------------------- jiaxing2 · 2020-05-13 11:19 Quote from: Thaddy on May 13, 2020, 11:58:52 amBart, For mode objfpc this should work. In mode delphi the @'s are not necessary and should also work. What about mode FPC? ---------------------------------------------------------------------- jiaxing2 · 2020-05-13 11:20 Quote from: Bart on May 13, 2020, 11:02:47 amMaybe something like this? (untested code) 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  TMyFunc = function(x: integer): integer; function foo(x: integer):integer;begin  result := x*x;end; function bar(x: integer): integer;begin  result := -x;end; var  MyFunc: TMyFunc;begin  ...  if SomeCondition then    MyFunc := @foo  else    MyFunc := @bar;  writeln('MyFunc(2) = ',MyFunc(2));end. Bart Thank you. I'm completely wrong about procedure type. ---------------------------------------------------------------------- Zoran · 2020-05-13 11:22 Quote from: jiaxing2 on May 13, 2020, 01:19:27 pmQuote from: Thaddy on May 13, 2020, 11:58:52 amBart, For mode objfpc this should work. In mode delphi the @'s are not necessary and should also work. What about mode FPC? What about reading the documentation? https://www.freepascal.org/docs-html/current/prog/progse72.html ---------------------------------------------------------------------- jiaxing2 · 2020-05-13 11:26 Quote from: Zoran on May 13, 2020, 01:22:27 pmQuote from: jiaxing2 on May 13, 2020, 01:19:27 pmQuote from: Thaddy on May 13, 2020, 11:58:52 amBart, For mode objfpc this should work. In mode delphi the @'s are not necessary and should also work. What about mode FPC? What about reading the documentation? https://www.freepascal.org/docs-html/current/prog/progse72.html Sorry. Already read this many times but missed the needed information