Function Pointer in Delpni

program Project1;

{$APPTYPE CONSOLE}
{$R *.res}

uses
    System.SysUtils;

type
    TVoice = function(): String;

function WithAmericanDoll(): String;
begin
    Result := 'Oh yes, Oh, F M.';
end;

function WithJapanDoll(): String;
begin
    Result := 'ah, a~ah, eku..eku..';
end;

function MkLove(voice: TVoice): String;
begin
    Result := voice();
end;
var
    temp: String;
begin
    try
        { TODO -oUser -cConsole Main : Insert code here }
        Writeln('1.AmericanDoll.');
        Writeln('    ' + MkLove(WithAmericanDoll));
        Writeln('1.JapanDoll.');
        Writeln('    ' + MkLove(WithJapanDoll));
        Readln;
    except
        on E: Exception do
            Writeln(E.ClassName, ': ', E.Message);
    end;

end.
原文地址:https://www.cnblogs.com/cause/p/3406091.html