7

I tried to use Delphi's syntax for anonymous methods:

type
    fun = reference to function(): Integer;

Fpc shows a syntax error:

Error: Identifier not found "reference"

What's the Free Pascal equivalent to Delphi's anonymous methods, if any?

kludg
  • 27,213
  • 5
  • 67
  • 118
mcandre
  • 22,868
  • 20
  • 88
  • 147

1 Answers1

6

Anonymous methods are not implemented in FreePascal. The list of such features is here.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • To this reading this in the future: greetings from 2011. Maybe this feature has been implemented in the meanwhile. Checking the list of features is probably a good idea indeed. – Wouter van Nifterick Oct 17 '11 at 22:50
  • 2
    @Wouter: Good point, but unnecessary, as David's post will have a datestamp on it within a few days. – Mason Wheeler Oct 17 '11 at 23:44
  • It already has, even when it still looks like just a time. When you hover over it, you get the full timestamp... – Marjan Venema Oct 18 '11 at 06:23
  • Free Pascal 2.6 and 2.7.1 do support ISO style nested procedures, where you can pass nested procedures to external procedures without lowlevel shenigans, and they can access their parent's vars. (which is a form of state capture too). I also updated the status on the ansistring (codepage) feature. – Marco van de Voort Oct 18 '11 at 09:31
  • @Marco I don't quite understand what you are saying here. The variable capture is just for the lifetime of the call to an external procedure, is that right? Is that what you are saying? – David Heffernan Oct 18 '11 at 09:36
  • 1
    Yes, but the external procedure can also pass it on, iow that whole codepath. It must not be referenced after the original procedure returns though. It is not the same as anonymous methods (which capture is more dynamical), but it falls in the same category of functions, and some needs can be fulfilled by it, for passing custom code+data to general enumerator functions. Turbo Vision in Turbo times would really have benefited from it (TCollection.foreacH) – Marco van de Voort Oct 18 '11 at 09:46