修改源码,直接把大写金额转换函数加进了FR_CLASS单元,用时设置表达式就行了,在可用函数中选择所加的MONEYCONVERT就行了,呵呵。
constructor TfrStdFunctionLibrary.Create;
var
rsAggregate, rsDateTime, rsString, rsOther, rsMath, rsBool, rsInterpr: string;
begin
inherited Create;
with Listdo
begin
Add('AVG');
Add('COUNT');
Add('DAYOF');
Add('FORMATDATETIME');
Add('FORMATFLOAT');
Add('FORMATTEXT');
Add('INPUT');
Add('LENGTH');
Add('LOWERCASE');
Add('MAX');
Add('MAXNUM');
Add('MESSAGEBOX');
Add('MIN');
Add('MINNUM');
Add('MONEYCONVERT');
//金额由小写转换为大写。
Add('MONTHOF');
Add('NAMECASE');
Add('POS');
Add('SUM');
Add('TRIM');
Add('UPPERCASE');
Add('YEAROF');
//edit 2003-11-27
end;
rsAggregate := frLoadStr(SAggregateCategory);
rsDateTime := frLoadStr(SDateTimeCategory);
rsString := frLoadStr(SStringCategory);
rsOther := frLoadStr(SOtherCategory);
rsMath := frLoadStr(SMathCategory);
rsBool := frLoadStr(SBoolCategory);
rsInterpr := frLoadStr(SIntrpCategory);
AddFunctionDesc('AVG', rsAggregate, frLoadStr(SDescriptionAVG));
AddFunctionDesc('COUNT', rsAggregate, frLoadStr(SDescriptionCOUNT));
AddFunctionDesc('DAYOF', rsDateTime, frLoadStr(SDescriptionDAYOF));
AddFunctionDesc('FORMATDATETIME', rsString, frLoadStr(SDescriptionFORMATDATETIME));
AddFunctionDesc('FORMATFLOAT', rsString, frLoadStr(SDescriptionFORMATFLOAT));
AddFunctionDesc('FORMATTEXT', rsString, LoadStr(SDescriptionFORMATTEXT));
AddFunctionDesc('INPUT', rsOther, frLoadStr(SDescriptionINPUT));
AddFunctionDesc('LENGTH', rsString, frLoadStr(SDescriptionLENGTH));
AddFunctionDesc('LOWERCASE', rsString, frLoadStr(SDescriptionLOWERCASE));
AddFunctionDesc('MAX', rsAggregate, frLoadStr(SDescriptionMAX));
AddFunctionDesc('MIN', rsAggregate, frLoadStr(SDescriptionMIN));
AddFunctionDesc('MONTHOF', rsDateTime, frLoadStr(SDescriptionMONTHOF));
AddFunctionDesc('NAMECASE', rsString, frLoadStr(SDescriptionNAMECASE));
AddFunctionDesc('STRTODATE', rsDateTime, frLoadStr(SDescriptionSTRTODATE));
AddFunctionDesc('STRTOTIME', rsDateTime, frLoadStr(SDescriptionSTRTOTIME));
AddFunctionDesc('SUM', rsAggregate, frLoadStr(SDescriptionSUM));
AddFunctionDesc('TRIM', rsString, frLoadStr(SDescriptionTRIM));
AddFunctionDesc('UPPERCASE', rsString, frLoadStr(SDescriptionUPPERCASE));
AddFunctionDesc('YEAROF', rsDateTime, frLoadStr(SDescriptionYEAROF));
AddFunctionDesc('MAXNUM', rsMath, frLoadStr(SDescriptionMAXNUM));
AddFunctionDesc('MINNUM', rsMath, frLoadStr(SDescriptionMINNUM));
AddFunctionDesc('POS', rsString, frLoadStr(SDescriptionPOS));
AddFunctionDesc('MESSAGEBOX', rsOther, frLoadStr(SDescriptionMESSAGEBOX));
// Other standard functions not included in this library
AddFunctionDesc('IF', rsOther, frLoadStr(SDescriptionIF));
AddFunctionDesc('COPY', rsString, frLoadStr(SDescriptionCOPY));
AddFunctionDesc('MOD', rsMath, frLoadStr(SDescriptionMOD));
AddFunctionDesc('STR', rsString, frLoadStr(SDescriptionSTR));
AddFunctionDesc('NOT', rsBool, frLoadStr(SDescriptionNOT));
AddFunctionDesc('AND', rsBool, frLoadStr(SDescriptionAND));
AddFunctionDesc('OR', rsBool, frLoadStr(SDescriptionOR));
AddFunctionDesc('ROUND', rsMath, frLoadStr(SDescriptionROUND));
AddFunctionDesc('FRAC', rsMath, frLoadStr(SDescriptionFRAC));
AddFunctionDesc('INT', rsMath, frLoadStr(SDescriptionINT));
AddFunctionDesc('TRUE', rsBool, frLoadStr(SDescriptionTRUE));
AddFunctionDesc('FALSE', rsBool, frLoadStr(SDescriptionFALSE));
// Special functions
AddFunctionDesc('PAGE#', rsOther, frLoadStr(SDescriptionPAGE));
AddFunctionDesc('DATE', rsDateTime, frLoadStr(SDescriptionDATE));
AddFunctionDesc('TIME', rsDateTime, frLoadStr(SDescriptionTIME));
AddFunctionDesc('LINE#', rsOther, frLoadStr(SDescriptionLINE));
AddFunctionDesc('LINETHROUGH#', rsOther, frLoadStr(SDescriptionLINETHROUGH));
AddFunctionDesc('COLUMN#', rsOther, frLoadStr(SDescriptionCOLUMN));
AddFunctionDesc('TOTALPAGES', rsOther, frLoadStr(SDescriptionTOTALPAGES));
// Interpreter
AddFunctionDesc('MROK', rsInterpr, frLoadStr(SDescriptionMROK));
AddFunctionDesc('MRCANCEL', rsInterpr, frLoadStr(SDescriptionMRCANCEL));
AddFunctionDesc('CURY', rsInterpr, frLoadStr(SDescriptionCURY));
AddFunctionDesc('FREESPACE', rsInterpr, frLoadStr(SDescriptionFREESPACE));
AddFunctionDesc('FINALPASS', rsInterpr, frLoadStr(SDescriptionFINALPASS));
AddFunctionDesc('PAGEHEIGHT', rsInterpr, frLoadStr(SDescriptionPAGEHEIGHT));
AddFunctionDesc('PAGEWIDTH', rsInterpr, frLoadStr(SDescriptionPAGEWIDTH));
AddFunctionDesc('PROGRESS', rsInterpr, frLoadStr(SDescriptionPROGRESS));
AddFunctionDesc('MODALRESULT', rsInterpr, frLoadStr(SDescriptionMODALRESULT));
AddFunctionDesc('STOPREPORT', rsInterpr, frLoadStr(SDescriptionSTOPREPORT));
AddFunctionDesc('NEWPAGE', rsInterpr, frLoadStr(SDescriptionNEWPAGE));
AddFunctionDesc('NEWCOLUMN', rsInterpr, frLoadStr(SDescriptionNEWCOLUMN));
AddFunctionDesc('SHOWBAND', rsInterpr, frLoadStr(SDescriptionSHOWBAND));
AddFunctionDesc('INC', rsInterpr, frLoadStr(SDescriptionINC));
AddFunctionDesc('DEC', rsInterpr, frLoadStr(SDescriptionDEC));
//edit 2003-11-27
AddFunctionDesc('MONEYCONVERT', rsMath, 'MONEYCONVERT(,,)/Small 指小写的金额;WeiShu指小写金额的小数的位数;aPrefix指负值前缀!');
end;
//edit 2003-11-27
function MONEYCONVERT(const Small:do
uble;
WeiShu: integer = 2;
aPrefix: pChar = nil): Variant;
forward;
procedure TfrStdFunctionLibrary.DoFunction(FNo: Integer;
p1, p2, p3: Variant;
var val: Variant);
var
at: Integer;
s: string;
Want: TfrBandType;
b: TfrBand;
v, v1: Variant;
begin
at := atNone;
val := '0';
case FNo of
0: at := atAvg;
// 1: at := atCount;
2: val := StrToInt(FormatDateTime('d', frParser.Calc(p1)));
3: val := FormatDateTime(frParser.Calc(p1), frParser.Calc(p2));
4: val := FormatFloat(frParser.Calc(p1), frParser.Calc(p2));
5: val := FormatMaskText(frParser.Calc(p1) + ';0;
', frParser.Calc(p2));
6: val := InputBox('', frParser.Calc(p1), frParser.Calc(p2));
7: val := Length(frParser.Calc(p1));
8: val := AnsiLowerCase(frParser.Calc(p1));
9: at := atMax;
10:
begin
v := frParser.Calc(p1);
v1 := frParser.Calc(p2);
if v > v1 then
val := v else
val := v1;
end;
11: val := Application.MessageBox(PChar(string(frParser.Calc(p1))),
PChar(string(frParser.Calc(p2))), frParser.Calc(p3));
12: at := atMin;
13:
begin
v := frParser.Calc(p1);
v1 := frParser.Calc(p2);
if v < v1 then
val := v else
val := v1;
end;
14: val := MONEYCONVERT(frParser.Calc(p1), frParser.Calc(p2), pchar(Trim(p3)));
15: val := StrToInt(FormatDateTime('m', frParser.Calc(p1)));
16:
begin
s := AnsiLowerCase(frParser.Calc(p1));
if Length(s) > 0 then
val := AnsiUpperCase(s[1]) + Copy(s, 2, Length(s) - 1) else
val := '';
end;
17: val := Pos(frParser.Calc(p1), frParser.Calc(p2));
18: at := atSum;
19: val := Trim(frParser.Calc(p1));
20: val := AnsiUpperCase(frParser.Calc(p1));
21: val := StrToInt(FormatDateTime('yyyy', frParser.Calc(p1)));
end;
if at <> atNone then
begin
s := p2;
if at = atCount then
begin
s := p1;
p3 := p2;
end;
if InitAggregate then
begin
if s = '' then
begin
Want := btNone;
case CurBand.Typ of
btPageFooter, btMasterFooter, btGroupFooter, btReportSummary:
Want := btMasterData;
btDetailFooter:
Want := btDetailData;
btSubdetailFooter:
Want := btSubdetailData;
btCrossFooter:
Want := btCrossData;
end;
if AggrBand.Typ <> Want then
Exit else
s := AggrBand.Name;
end;
// format is: BandName # AggrTyp # Expression # IncludeNonVisible #
// for Count: BandName # AggrTyp # NotUsed # IncludeNonVisible #
if AnsiCompareText(AggrBand.Name, Trim(s)) = 0 then
begin
s := CurBand.Name;
if (CurBand.Typ <> btCrossFooter) and CurBand.HasCross then
s := '0' + #1 + s;
if at = atMin then
v := 1E300 else
v := 0;
AggrBand.AddAggregateValue(s + #1 + Chr(at) + #1 + p1 + #1 + p3 + #1, v);
CurBand.AggrBand := AggrBand;
end;
end
else
if CurBand.AggrBand <> nil then
begin
b := CurBand;
s := b.Name;
if b.Typ = btCrossData then
begin
b := b.AggrBand;
s := IntToStr(CurPage.ColPos) + #1 + b.Name;
end;
val := b.AggrBand.GetAggregateValue(s + #1 + Chr(at) + #1 + p1 + #1 + p3 + #1);
end;
end;
end;
//edit 2003-11-27
function MONEYCONVERT(const Small:do
uble;
WeiShu: integer = 2;
aPrefix: pChar = nil): Variant;
var
SmallMonth, BigMonth, Prefix, FormatStr: string;
Wei1, QianWei1: string[2];
QianWei, DianWeiZhi, Qian: integer;
begin
if (WeiShu < 0) or (Weishu > 4) then
begin
//如果保留的小数位非法,则退出。
Result := '';
Exit;
end;
try
{修改参数令值更精确}
QianWei := -1 * Weishu;
//-2;
//小数点后的位置,需要的话也可以改动-2值
case Weishu of
0: FormatStr := '0';
1: FormatStr := '0.0';
2: FormatStr := '0.00';
3: FormatStr := '0.000';
4: FormatStr := '0.0000';
end;
if Small >= 0 then
Smallmonth := formatfloat(FormatStr, small) //转换成货币形式,需要的话小数点后多加几个零
else
Smallmonth := formatfloat(FormatStr, -1 * small);
DianWeiZhi := pos('.', Smallmonth);
//小数点的位置。
//循环小写货币的每一位,从小写的右边位置到左边。
for Qian := length(Smallmonth)do
wnto 1do
begin
if Qian <> DianWeiZhi then
//如果读到的不是小数点就继续
begin
case strtoint(copy(Smallmonth, Qian, 1)) of //位置上的数转换成大写
1: Wei1 := '壹';
2: Wei1 := '贰';
3: Wei1 := '叁';
4: Wei1 := '肆';
5: Wei1 := '伍';
6: Wei1 := '陆';
7: Wei1 := '柒';
8: Wei1 := '捌';
9: Wei1 := '玖';
0: Wei1 := '零';
end;
case QianWei of //判断大写位置,可以继续增大到double类型的最大值
-4: QianWei1 := '毫';
-3: QianWei1 := '厘';
-2: QianWei1 := '分';
-1: QianWei1 := '角';
0: QianWei1 := '元';
1: QianWei1 := '拾';
2: QianWei1 := '佰';
3: QianWei1 := '千';
4: QianWei1 := '万';
5: QianWei1 := '拾';
6: QianWei1 := '佰';
7: QianWei1 := '千';
8: QianWei1 := '亿';
9: QianWei1 := '拾';
10: QianWei1 := '佰';
11: QianWei1 := '千';
end;
inc(QianWei);
BigMonth := Wei1 + QianWei1 + BigMonth;
//组合成大写金额
end;
end;
except
Result := '';
end;
Result := '';
if Small < 0 then
begin
if aPrefix = nil then
Prefix := '欠缴'
else
Prefix := aPrefix;
BigMonth := Prefix + BigMonth;
Result := BigMonth;
end
else
Result := BigMonth;
end;
{ TInterpretator }