mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-15 06:39:31 +02:00
33 lines
557 B
ObjectPascal
33 lines
557 B
ObjectPascal
program tanonfunc15;
|
|
|
|
{$mode objfpc}{$H+}
|
|
{$modeswitch anonymousfunctions}
|
|
{$modeswitch functionreferences}
|
|
|
|
{ "ClassName" inside an anonymous function inside a method returns the
|
|
"ClassName" of the surrounding class }
|
|
|
|
type
|
|
tstrfunc = reference to function : string;
|
|
|
|
TTest = class
|
|
function Test: tstrfunc;
|
|
end;
|
|
|
|
function TTest.Test: tstrfunc;
|
|
begin
|
|
Result := function: string begin result := classname; end;
|
|
end;
|
|
|
|
var
|
|
f: tstrfunc;
|
|
t: TTest;
|
|
begin
|
|
t := TTest.Create;
|
|
f := t.Test;
|
|
if f() <> 'TTest' then
|
|
Halt(1);
|
|
t.Free;
|
|
end.
|
|
|