可以用case 实现。
function StringName Function Name
--------------------------------------------
StrGetFloat GetFloat
case function StringName of
StrGetFloat : GetFloat;
end;
case 中使用字符串的例子如下:
function CaseString (const s: string;
const x: array of string): Integer;
var i: Integer;
begin
Result:= -1;
// Default return parameter
for i:= Low (x) to High (x)do
begin
if s = x then
begin
Result:= i;
Exit;
end;
end;
end;
search:= 'delphi3000';
case CaseString (search, ['delphi3000',
'delphipages',
'Torry's']) of
0: s:= 'Excellent!';
1: s:= 'Good source';
2: s:= 'Not bad!';
end;