Forum > FPC development

[Function References ] not work on MACOS FPC 3.3.1

(1/1)

cai:
{$modeswitch functionreferences}

=============================
type
  TProc =reference to procedure;
========================
Compile & print out
Error: Identifier not found "reference "

cai:
OK,I was wrong!
it is cause by {$mode objfpc}


===================
failed code
---------

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$modeswitch functionreferences}{$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs; type   { TForm1 }   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.frm} type  TProc =reference to procedure; { TForm1 } procedure TForm1.FormCreate(Sender: TObject);var  P: TProc;begin end; end. 


==============
succeed code
---------------

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$modeswitch functionreferences}//{$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs; type   { TForm1 }   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.frm} type  TProc =reference to procedure; { TForm1 } procedure TForm1.FormCreate(Sender: TObject);var  P: TProc;begin end; end.  
why?

cai:
I was wrong! again! :-[
{$mode objfpc} should be put in front of {$modeswitch}


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$mode objfpc}{$H+}{$modeswitch functionreferences} 

Thaddy:
The reason being that {$mode} is actually a set of {$modeswitches}.
It is documented that for the time being {$modeswitch functionreferences} does not belong to any mode yet.
This may change in the future, though.

https://wiki.freepascal.org/FPC_New_Features_Trunk#Support_for_Function_References_and_Anonymous_Functions
https://forum.lazarus.freepascal.org/index.php/topic,59468.0.html

It is likely the modeswitch  will part of {$mode delphi} and {$mode objfpc} in the future.
https://forum.lazarus.freepascal.org/index.php/topic,59468.msg443373.html#msg443373
( but that' s why it is in trunk only: it needs testing and it needs to mature )

PascalDragon:

--- Quote from: cai on April 01, 2023, 06:44:18 am ---I was wrong! again! :-[
{$mode objfpc} should be put in front of {$modeswitch}


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$mode objfpc}{$H+}{$modeswitch functionreferences} 
--- End quote ---

A {$mode ...} directive resets any {$modeswitch ...} directive.

Navigation

[0] Message Index

Go to full version