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.

 

posted @ 2013-11-04 11:19  oszhouzhb  阅读(181)  评论(0编辑  收藏  举报