FastReport:我写了一个将金额数字转换成大写金额的程序,但如何在fastreport调用它呢? 在线等!!! ( 积分: 20 )

  • 主题发起人 主题发起人 tobey
  • 开始时间 开始时间
T

tobey

Unregistered / Unconfirmed
GUEST, unregistred user!
我在fastreport报表里用到一个将金额数字转换成大写的函数(Funtion),我把它写在Memo
中的Text Editor中,程序如下:
Function RealToChineseMoneyString(Amount : real) : String;
var
Dollars : LongInt;
cents : Integer;
const EPSILON = 0.0000001;
function Num2Str(Num: LongInt): String;
Const Ten = 10;
Hundred = 100;
Thousand = 1000;
TenThousand = 10000;
HundredMillion = 100000000;

begin
if Num >= HundredMillion then
begin
if (Num mod HundredMillion) = 0 then
Result := Num2Str(Num div HundredMillion) + '货'
else if (Num mod HundredMillion) < (HundredMillion/10) then
Result := Num2Str(Num div HundredMillion) + '货箂' +
Num2Str(Num mod HundredMillion)
else
Result := Num2Str(Num div HundredMillion) + '货' +
Num2Str(Num mod HundredMillion);
end
else if Num >= TenThousand then
begin
if (Num mod TenThousand) = 0 then
Result := Num2Str(Num div TenThousand) + '窾'
else if (Num mod TenThousand) < (TenThousand/10) then
Result := Num2Str(Num div TenThousand) + '窾箂' +
Num2Str(Num mod TenThousand)
else
Result := Num2Str(Num div TenThousand) + '窾' +
Num2Str(Num mod TenThousand);
end
else if Num >= thousand then
begin
if (Num mod thousand) = 0 then
Result := Num2Str(Num div thousand) + '?'
else if (Num mod thousand) < (thousand/10) then
Result := Num2Str(Num div Thousand) + '?箂' +
Num2Str(Num mod Thousand)
else
Result := Num2Str(Num div Thousand) + '?' +
Num2Str(Num mod Thousand);
end
else if Num >= hundred then
begin
if (Num mod hundred) = 0 then
Result := Num2Str(Num div hundred) + 'ㄕ'
else if (Num mod hundred) < (hundred/10) then
Result := Num2Str(Num div hundred) + 'ㄕ箂' +
Num2Str(Num mod hundred)
else
Result := Num2Str(Num div hundred) + 'ㄕ' +
Num2Str(Num mod hundred);
end
else if Num >= Ten then
begin
if (Num mod Ten) = 0 then
Result := Num2Str(Num div Ten) + '珺'
else if (Num mod Ten) < (Ten/10) then
Result := Num2Str(Num div Ten) + '珺' +
Num2Str(Num mod Ten)
else
Result := Num2Str(Num div Ten) + '珺' +
Num2Str(Num mod Ten);
end
else
begin
case Num of
0: Result := '箂';
1: Result := '滁';
2: Result := '禠';
3: Result := '把';
4: Result := '竩';
5: Result := 'ヮ';
6: Result := '嘲';
7: Result := '琺';
8: Result := '?';
9: Result := '╤';
end;
end;
end {Num2Str};
begin
Dollars := Trunc(Amount);
cents := Round(100*Frac(Amount));
if not ((Dollars > EPSILON) or (Cents > EPSILON)) then
begin
Result := '箂';
Exit;
end;
if Dollars > EPSILON then
Result := Num2Str(Dollars);
Result := Result + '蛾';
if cents > EPSILON then
Result := Result + Num2Str(cents) + '?'
else
Result := Result + 'タ';
end;

然后在上面调用如下:
[ RealToChineseMoneyString(table1.fieldByName('TotalAmount).AsFloat)]
为什么会出错呢??
希望各位智囊高手指正一下,在线等!!!
 
我在fastreport报表里用到一个将金额数字转换成大写的函数(Funtion),我把它写在Memo
中的Text Editor中,程序如下:
Function RealToChineseMoneyString(Amount : real) : String;
var
Dollars : LongInt;
cents : Integer;
const EPSILON = 0.0000001;
function Num2Str(Num: LongInt): String;
Const Ten = 10;
Hundred = 100;
Thousand = 1000;
TenThousand = 10000;
HundredMillion = 100000000;

begin
if Num >= HundredMillion then
begin
if (Num mod HundredMillion) = 0 then
Result := Num2Str(Num div HundredMillion) + '货'
else if (Num mod HundredMillion) < (HundredMillion/10) then
Result := Num2Str(Num div HundredMillion) + '货箂' +
Num2Str(Num mod HundredMillion)
else
Result := Num2Str(Num div HundredMillion) + '货' +
Num2Str(Num mod HundredMillion);
end
else if Num >= TenThousand then
begin
if (Num mod TenThousand) = 0 then
Result := Num2Str(Num div TenThousand) + '窾'
else if (Num mod TenThousand) < (TenThousand/10) then
Result := Num2Str(Num div TenThousand) + '窾箂' +
Num2Str(Num mod TenThousand)
else
Result := Num2Str(Num div TenThousand) + '窾' +
Num2Str(Num mod TenThousand);
end
else if Num >= thousand then
begin
if (Num mod thousand) = 0 then
Result := Num2Str(Num div thousand) + '?'
else if (Num mod thousand) < (thousand/10) then
Result := Num2Str(Num div Thousand) + '?箂' +
Num2Str(Num mod Thousand)
else
Result := Num2Str(Num div Thousand) + '?' +
Num2Str(Num mod Thousand);
end
else if Num >= hundred then
begin
if (Num mod hundred) = 0 then
Result := Num2Str(Num div hundred) + 'ㄕ'
else if (Num mod hundred) < (hundred/10) then
Result := Num2Str(Num div hundred) + 'ㄕ箂' +
Num2Str(Num mod hundred)
else
Result := Num2Str(Num div hundred) + 'ㄕ' +
Num2Str(Num mod hundred);
end
else if Num >= Ten then
begin
if (Num mod Ten) = 0 then
Result := Num2Str(Num div Ten) + '珺'
else if (Num mod Ten) < (Ten/10) then
Result := Num2Str(Num div Ten) + '珺' +
Num2Str(Num mod Ten)
else
Result := Num2Str(Num div Ten) + '珺' +
Num2Str(Num mod Ten);
end
else
begin
case Num of
0: Result := '箂';
1: Result := '滁';
2: Result := '禠';
3: Result := '把';
4: Result := '竩';
5: Result := 'ヮ';
6: Result := '嘲';
7: Result := '琺';
8: Result := '?';
9: Result := '╤';
end;
end;
end {Num2Str};
begin
Dollars := Trunc(Amount);
cents := Round(100*Frac(Amount));
if not ((Dollars > EPSILON) or (Cents > EPSILON)) then
begin
Result := '箂';
Exit;
end;
if Dollars > EPSILON then
Result := Num2Str(Dollars);
Result := Result + '蛾';
if cents > EPSILON then
Result := Result + Num2Str(cents) + '?'
else
Result := Result + 'タ';
end;

然后在上面调用如下:
[ RealToChineseMoneyString(table1.fieldByName('TotalAmount).AsFloat)]
为什么会出错呢??
希望各位智囊高手指正一下,在线等!!!
 
程序中有些中文繁体字显示不了,这没问题,我在delphi中测试通过,没问题,但在fastreport 中就不行,求赐教!
 
下面这个是你需要的,看“在fastreport里使用自定义函数”
作者?: fenian
标题?: FastReport自整理技巧
http://www.delphibbs.com/keylife/iblog_show.asp?xid=13640
 
其实你可以在fastreport报表中放一个memo,然后在主程序中执行你的转换函数,
把得到的大写再传给fastreport
 
你发来的函数看过了,你在button.click上添加这一句就可以了:
frreport1.Dictionary.Variables['totalamountUPCASEChinese'] :=QuotedStr(RealToChineseMoneyString(table1.fieldByName('TotalAmount').AsFloat));
 
多人接受答案了。
 
后退
顶部