// 然后写了一个用这个类型作为参数的过程 procedure MyFunc(f: TSomeFunc); begin if f('aaaa', 123) == true then ShowMessage('ok'); end;
然后这样调用: procedure TYYY.Test(); begin MyFunc( function (str: string; val:Integer):boolean begin Result := False; if val == StrToInt(str) Result := True; end ); end;
// 就会编译不过 报 E2010 Incompatible types: 'TSomeFunc' and 'Procedure'
// 但是如果 把函数写在外面,然后传入函数名,就可以 // 比如先写成有名函数 function testSomeFunc(str: string; val:Integer):boolean; begin Result := False; if val == StrToInt(str) Result := True; end;
//然后这样调用 就完全没有问题 procedure TYYY.Test(); begin MyFunc(testSomeFunc); end;