W
water201
Unregistered / Unconfirmed
GUEST, unregistred user!
1、在Form中测试该函数有效果,可以正常将小写数字转换成大写金额。
2、运行程序,开设计模式,在fastreport的报表设计器中可以看到该自定义函数,但转换的结果这是空白(没有报错)。
相关函数和代码如下,请各位朋友指点
{函数定义及增加到报表部分}
function MoneyCn(mMoney: real): WideString;
var
P: Integer;
begin
if mMoney = 0 then
begin
Result := '无';
Exit;
end;
Result := NumberCn(Round(mMoney * 100) / 100);
Result := StringReplace(Result, '一', '壹', [rfReplaceAll]);
Result := StringReplace(Result, '二', '贰', [rfReplaceAll]);
Result := StringReplace(Result, '三', '叁', [rfReplaceAll]);
Result := StringReplace(Result, '四', '肆', [rfReplaceAll]);
Result := StringReplace(Result, '五', '伍', [rfReplaceAll]);
Result := StringReplace(Result, '六', '陆', [rfReplaceAll]);
Result := StringReplace(Result, '七', '柒', [rfReplaceAll]);
Result := StringReplace(Result, '八', '捌', [rfReplaceAll]);
Result := StringReplace(Result, '九', '玖', [rfReplaceAll]);
Result := StringReplace(Result, '九', '玖', [rfReplaceAll]);
Result := StringReplace(Result, '十', '拾', [rfReplaceAll]);
Result := StringReplace(Result, '百', '佰', [rfReplaceAll]);
Result := StringReplace(Result, '千', '仟', [rfReplaceAll]);
P := Pos('点', Result);
if P > 0 then
begin
Insert('分', Result, P + 3);
Insert('角', Result, P + 2);
Result := StringReplace(Result, '点', '圆', [rfReplaceAll]);
Result := StringReplace(Result, '角分', '角', [rfReplaceAll]);
Result := StringReplace(Result, '零分', '', [rfReplaceAll]);
Result := StringReplace(Result, '零角', '', [rfReplaceAll]);
Result := StringReplace(Result, '分角', '', [rfReplaceAll]);
if Copy(Result, 1, 2) = '零圆' then
Result := StringReplace(Result, '零圆', '', [rfReplaceAll]);
end else
Result := Result + '圆整';
Result := '人民币{大写}:' + Result;
end;
{ MoneyCn }
///////End Source
function frxReport1UserFunction( const MethodName: String ;var Params: Variant): Variant;
begin
if MethodName = 'MONEYCN' then
Result := MoneyCn(Params[0]);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
frxReport1.AddFunction('function MoneyCn(mMoney: real): WideString;');
end;
{下面的的文本能正常转换}
procedure TForm1.DBEdit3Change(Sender: TObject);
begin
edit5.text:=MoneyCn(2345);
end;
2、运行程序,开设计模式,在fastreport的报表设计器中可以看到该自定义函数,但转换的结果这是空白(没有报错)。
相关函数和代码如下,请各位朋友指点
{函数定义及增加到报表部分}
function MoneyCn(mMoney: real): WideString;
var
P: Integer;
begin
if mMoney = 0 then
begin
Result := '无';
Exit;
end;
Result := NumberCn(Round(mMoney * 100) / 100);
Result := StringReplace(Result, '一', '壹', [rfReplaceAll]);
Result := StringReplace(Result, '二', '贰', [rfReplaceAll]);
Result := StringReplace(Result, '三', '叁', [rfReplaceAll]);
Result := StringReplace(Result, '四', '肆', [rfReplaceAll]);
Result := StringReplace(Result, '五', '伍', [rfReplaceAll]);
Result := StringReplace(Result, '六', '陆', [rfReplaceAll]);
Result := StringReplace(Result, '七', '柒', [rfReplaceAll]);
Result := StringReplace(Result, '八', '捌', [rfReplaceAll]);
Result := StringReplace(Result, '九', '玖', [rfReplaceAll]);
Result := StringReplace(Result, '九', '玖', [rfReplaceAll]);
Result := StringReplace(Result, '十', '拾', [rfReplaceAll]);
Result := StringReplace(Result, '百', '佰', [rfReplaceAll]);
Result := StringReplace(Result, '千', '仟', [rfReplaceAll]);
P := Pos('点', Result);
if P > 0 then
begin
Insert('分', Result, P + 3);
Insert('角', Result, P + 2);
Result := StringReplace(Result, '点', '圆', [rfReplaceAll]);
Result := StringReplace(Result, '角分', '角', [rfReplaceAll]);
Result := StringReplace(Result, '零分', '', [rfReplaceAll]);
Result := StringReplace(Result, '零角', '', [rfReplaceAll]);
Result := StringReplace(Result, '分角', '', [rfReplaceAll]);
if Copy(Result, 1, 2) = '零圆' then
Result := StringReplace(Result, '零圆', '', [rfReplaceAll]);
end else
Result := Result + '圆整';
Result := '人民币{大写}:' + Result;
end;
{ MoneyCn }
///////End Source
function frxReport1UserFunction( const MethodName: String ;var Params: Variant): Variant;
begin
if MethodName = 'MONEYCN' then
Result := MoneyCn(Params[0]);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
frxReport1.AddFunction('function MoneyCn(mMoney: real): WideString;');
end;
{下面的的文本能正常转换}
procedure TForm1.DBEdit3Change(Sender: TObject);
begin
edit5.text:=MoneyCn(2345);
end;