自定义函数如何调用
想把这个函数存作一个公共文件.PAS文件,而其它单元用的时候再调用,怎么做,麻烦告诉我调用的具体位置及方法,最好举一个例子
//自定义四舍五入函数
function sswr(sj:real;weishu:integer):real;
var jinwei:real;
begin
if sj>=0 then
jinwei:=sj*intpower(10,weishu)+0.5
else
jinwei:=sj*intpower(10,weishu)-0.5;
Result :=trunc(jinwei)/intpower(10,weishu); //Result为返回值
end;
//四舍五入函数
[解决办法]
1、定义一个自用单元文件:Myown.pas;
Unit Myown;
......
2、在单元文件中定义函数:
(1)interface部分定义文件头;
function sswr(sj:real;weishu:integer):real;
(2)实现部分implementation定义函数实体
function sswr(sj:real;weishu:integer):real;
var jinwei:real;
begin
if sj>=0 then
jinwei:=sj*intpower(10,weishu)+0.5
else
jinwei:=sj*intpower(10,weishu)-0.5;
Result :=trunc(jinwei)/intpower(10,weishu); //Result为返回值
end;
3、在其它单元中加入
Uses Myown;
4、在单元中,直接调用:
N:=sswr(Na,10);