自定义函数总提示警告
function Agejisuan(birthday:string= '20070101 '):integer; //声明函数,计算年龄
function TForm1.Agejisuan(birthday:string):integer;//定义函数,计算年龄,参数格式为20070101
var nowstr,yearnow,monthnow,yearbirthday,monthbirthday:string;
begin
nowstr:=formatdatetime( 'yyyymmdd ',now());
yearnow:=copy(nowstr,1,4);
monthnow:=copy(nowstr,5,2);
yearbirthday:=copy(birthday,1,4);
monthbirthday:=copy(birthday,5,2);
if strtoint(monthbirthday)> strtoint(monthnow) then
Result:=strtoint(yearnow)-strtoint(yearbirthday)-1
else Result:=strtoint(yearnow)-strtoint(yearbirthday);
end;
刚开始运行正常,第二次就会出现“return value of function 'TForm1.Agejisuan 'might be undefined”为什么??
[解决办法]
在程序的type中加上一句:
function Agejisuan(birthday:string):integer;
你看每个过程在其中都有类型的声明,函数也应该有。