社区
C++ Builder
帖子详情
怎么把'TStrings'转换成 'WideString'?
sheyu8
2003-10-16 03:11:15
请写出具体作法!
...全文
74
5
打赏
收藏
怎么把'TStrings'转换成 'WideString'?
请写出具体作法!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
myy
2003-10-16
打赏
举报
回复
如果实在需要“WideStringList”,也有第三方写的 TWideStringList 类,你去找找。
IAMCDYY2003
2003-10-16
打赏
举报
回复
同意Wingsun(孙春阳)
Kabin
2003-10-16
打赏
举报
回复
没看清题目,不好意思
Kabin
2003-10-16
打赏
举报
回复
这样就ok
WideString(String URL);
Wingsun
2003-10-16
打赏
举报
回复
TStrings是一个String的集合,不是一个String所以它不能转换成为WideString。
除非你把TStrings中的数据拼成一个String然后才可以转换。
TStrings的Text属性就是TStrings中数据的集合。可以转换这个。
多看看help吧
大小写金额转换-源码
unit CnDigits;{-------------------------------------------------------------------- 货币数字转为为中文大写的组件 Version 1.31 by SNAKEJIAO 2003.4.13简介: 可以转化整数,浮点数,及时间日期型数据 配合别名列表可以进行语音合成,主要用于 东进中继卡中的PlayPrompt提示语音的合成 用于电话系统中播放金额,日期及时间 还有输入的数字序列,同时更多的应用于显示 销售系统中的打印发票时的中文大写金额字段email: jiaoguoqing26@21cn.com来自:爱数星星的猫, 时间:2003-9-17 没有习惯,有规定。给你看看人民银行的规定吧(说不定你还得改改^_^)。正确填写票据和结算凭证的基本规定 银行、单位和个人填写的各种票据和结算凭证是办理支付结算和现金收付的重要依据,直接关系到支付结算的准确、及时和安全。票据和结算凭证是银行、单位和个人凭以记载账务的会计凭证,是记载经济业务和明确经济责任的一种书面证明。因此,填写票据和结算凭证,必须做到标准化、规范化,要要素齐全、数字正确、字迹清晰、不错漏、不潦草,防止涂改。 一、中文大写金额数字应用正楷或行书填写,如壹(壹)、贰(贰)、叁、肆(肆)、伍(伍)、陆(陆)、柒、捌、玖、拾、佰、仟、万(万)、亿、元、角、分、零、整(正)等字样。不得用一、二(两)、三、四、五、六、七、八、九、十、念、毛、另(或0)填写,不得自造简化字。如果金额数字书写中使用繁体字,如貳、陸、億、萬、圓的,也应受理。 二、中文大写金额数字到“元”为止的,在“元”之后,应写“整”(或“正”)字,在“角”之后可以不写“整”(或“正”)字。大写金额数字有“分”的,“分”后面不写“整”(或“正”)字。 三、中文大写金额数字前应标明“人民币”字样,大写金额数字应紧接“人民币”字样填写,不得留有空白。大写金额数字前未印“人民币”字样的,应加填“人民币”三字。在票据和结算凭证大写金额栏内不得预印固定的“仟、佰、拾、万、仟、伯、拾、元、角、分”字样。 四、阿拉伯小写金额数字中有“0”时,中文大写应按照汉语语言规律、金额数字构成和防止涂改的要求进行书写。举例如下: (一)阿拉伯数字中间有“O”时,中文大写金额要写“零”字。如 ¥1,409.50,应写成人民币壹仟肆佰零玖元伍角。 (二)阿拉伯数字中间连续有几个“0”时,中文大写金额中间可以只写 一个“零”字。如¥6,007.14,应写成人民币陆仟零柒元壹角肆分。 (三)阿拉伯金额数字万位或元位是“0”,或者数字中间连续有几个“0”, 万位、元位也是“0’,但千位、角位不是“0”时,中文大写金额中 可以只写一个零字,也可以不写“零”字。如¥1,680.32,应写成 人民币壹仟陆佰捌拾元零叁角贰分,或者写成人民币壹仟陆佰捌拾元 叁角贰分;又如¥107,000.53,应写成人民币壹拾万柒仟元零伍角 叁分,或者写成人民币壹拾万零柒仟元伍角叁分。 (四)阿拉伯金额数字角位是“0”,而分位不是“0”时,中文大写金额 “元”后面应写“零”字。如¥16,409.02,应写成人民币壹万陆 仟肆佰零玖元零贰分;又如¥325.04,应写成人民币叁佰贰拾伍元 零肆分。 五、阿拉伯小写金额数字前面,均应填写入民币符号“¥”(或草写:)。阿拉伯小写金额数字要认真填写,不得连写分辨不清。 六、票据的出票日期必须使用中文大写。为防止变造票据的出禀日期,在填写月、日时,月为壹、贰和壹拾的,日为壹至玖和壹拾、贰拾和叁抬的,应在其前加“零”;日为抬壹至拾玖的,应在其前加“壹”。如1月15日,应写成零壹月壹拾伍日。再如10月20日,应写成零壹拾月零贰拾日。 七、票据出票日期使用小写填写的,银行不予受理。大写日期未按要求规范填写的,银行可予受理,但由此造成损失的,由出票入自行承担。--------------------------------------------------------------------}{ ‘NOTICE: uncomment following line to discard unused code !‘}{ ‘注意: 去掉下面这一行,可以抛弃收集的其它代码‘}// { discard_other_code}interfaceuses Windows, Messages, SysUtils, Classes, Math;type //类型定义 TDate = TDateTime; TTime = TDateTime; { 中文数字大写组件 by lichaohui } TCnDigits = class(TComponent) private Fda: Boolean; procedure SetDA(const Value: Boolean); procedure SetCnUP(const Value:
String
); protected FCurrVa: Currency; FCnUpDigits:
String
; FAlias: T
String
s; procedure SetCurrVa(const Value: Currency); procedure SetAlias(const Value: T
String
s); public { discard_other_code} //下面是肖杨的商场管理源码中的代码 //返加人民币的中文数值 class function other_RMB(NN:real):
string
; //其它的两个方法 class function other_SmallTOBig(small: real):
string
; class function other_XD(xx: currency):
string
; {} //下面是lichaohui的工具函数 class function LzhFmtInt(IntValue: Int64; IsYear: Boolean = False; SoftTone: Boolean = False):
String
; class function LzhFmtDigits(Digits:
String
):
String
; class function LzhFmtFloat(FloatValue: Extended; RoundPos: Integer = 8):
String
; class function LzhFmtCurrency(AValue: Currency):
String
; overload; class function LzhFmtCurrency(AValue: Int64):
String
; overload; class function LzhFmtDate(AValue: TDate; DigitsYear: Boolean = False):
String
; class function StdFmtDate(AValue: TDate; DigitsYear: Boolean = False):
String
; class function LzhFmtTime(AValue: TTime; HasSecond: Boolean = False):
String
; class function LzhFmtDateTime(AValue: TDateTime; DigitsYear: Boolean = False):
String
; class function StdFmtDateTime(AValue: TDateTime; DigitsYear: Boolean = False):
String
; //常用方法调用接口 function ChineseUpper(Curr: Currency):
String
; function ChineseDate(ADate: TDate; DigitsYear: Boolean = False):
String
; function ChineseTime(ATime: TTime; HasSecond: Boolean = False):
String
; //等价别名转化 function StrToAlias(S:
String
):
String
; function StrToAlias2(S:
String
):
String
; //构造和析构函数 constructor Create(AOwner: TComponent); overr
ide
; destructor Destroy; overr
ide
; published property CurrencyValue: Currency read FCurrVa write SetCurrVa; property CnUpperDigits:
String
read FCnUpDigits write SetCnUP stored False; property Alias: T
String
s read FAlias write SetAlias; property DefaultAlias: Boolean read Fda write SetDA; end;const DP: W
ide
String
= ‘零壹贰叁肆伍陆柒捌玖两负‘; DN: W
ide
String
= ‘点拾佰仟万拾佰仟亿拾佰仟万拾佰仟兆拾佰仟‘; CrNa: W
ide
String
= ‘元角分整‘; DtNa: W
ide
String
= ‘年月日时分秒‘;procedure Register;implementationprocedure Register;begin RegisterComponents(‘System‘, [TCnDigits]);end;{ TCnDigits }{ discard_other_code}class function TCnDigits.other_RMB(NN: real):
string
;var HZ, NS, NW, NA, N1, N2:
string
; LA, X, Nk:integer;begin //此行代码是为了修正小数位多于两位时生成的结果的错误 NN := Int(NN * 100) / 100; //下面的代码被lichaohui格式化整理 if NN > 9999999999999.99 then begin //MessageDlg(‘金额溢出。‘,mtError,[mbOk], 0); HZ := ‘‘; Result := HZ; exit; end; if NN = 0 then begin HZ := ‘零元‘; result := HZ; exit; end; NS := ‘零壹贰叁肆伍陆柒捌玖‘; NW := ‘分角元拾佰仟万拾佰仟亿拾佰仟万‘; NA := FloatToStr(NN * 100); LA := length(NA); X := 1; HZ := ‘‘; while X<=LA do begin NK := Ord(NA[x]) - Ord(‘0‘); N1 := Copy(NS, NK * 2 + 1, 2); N2 := Copy(NW, LA * 2 + 1 - X * 2, 2); if (NK = 0) AND ((N2 = ‘亿‘) OR( N2 = ‘万‘) OR( N2 = ‘元‘))then begin if copy(HZ,Length(HZ)-1,2) = ‘零‘ then HZ := copy(HZ, 1, length(HZ) - 2); if copy(HZ, Length(HZ) - 1, 2) = ‘亿‘ then if N2 = ‘元‘ then begin N1 := N2; N2 := ‘零‘; end else N2 := ‘‘ else begin N1 := N2; N2 := ‘零‘; end end else if NK=0 then begin if copy(HZ, length(HZ) - 1, 2)=‘零‘ then N1 := ‘‘; if N2=‘分‘ then begin if copy(HZ, length(HZ) - 1, 2)=‘零‘ then HZ := copy(HZ, 1, length(HZ) - 2) + ‘整‘ else HZ := HZ + ‘整‘; N1 := ‘‘; end; N2 := ‘‘; end; HZ := HZ + N1 + N2; X := X + 1 end; {end of while statement} Result := HZ;end;class function TCnDigits.other_SmallTOBig(small: real):
string
;var SmallMonth,BigMonth:
string
; wei1,qianwei1:
string
[2]; qianwei,dianweizhi,qian:integer;begin {------- 修改参数令值更精确 -------} {小数点后的位数,需要的话也可以改动该值} qianwei:=-2; {
转换成
货币形式,需要的话小数点后加多几个零} Smallmonth:=formatfloat(‘0.00‘,small); {---------------------------------} dianweizhi :=pos(‘.‘,Smallmonth);{小数点的位置} {循环小写货币的每一位,从小写的右边位置到左边} for qian:=length(Smallmonth) downto 1 do begin {如果读到的不是小数点就继续} if qiandianweizhi 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; {判断大写位置,可以继续增大到real类型的最大值,可是谁有那么多钱} case qianwei of -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; Result := BigMonth;end;class function TCnDigits.other_XD(xx: currency):
string
;var dx,ws:
string
; i,cd:integer; int:currency;begin int:=trunc(abs(xx)+0.005*100); cd:=length(currtostr(int)); dx:=‘零壹贰叁肆伍陆柒捌玖‘; ws:=‘分角元拾佰仟万拾佰仟亿拾佰仟‘; result:=‘‘; i:=1; while i 0) and (FracPart >= 10) then rs := rs + DP[1]; if (IntPart = 0) and (FracPart 0) then rs := ‘‘; if FracPart >= 10 then begin if FracPart mod 10 = 0 then rs := rs + DP[Jiao + 1] + CrNa[2] + CrNa[4] else rs := rs + DP[Jiao + 1] + CrNa[2] + DP[Fen + 1] + CrNa[3]; end else if FracPart > 0 then begin if IntPart = 0 then rs := rs + DP[Fen + 1] + CrNa[3] else rs := rs + DP[1] + DP[Fen + 1] + CrNa[3]; end else begin rs := rs + CrNa[4]; end; if AValue 0) and (FracPart >= 10) then rs := rs + DP[1]; if (IntPart = 0) and (FracPart 0) then rs := ‘‘; if FracPart >= 10 then begin if FracPart mod 10 = 0 then rs := rs + DP[Jiao + 1] + CrNa[2] + CrNa[4] else rs := rs + DP[Jiao + 1] + CrNa[2] + DP[Fen + 1] + CrNa[3]; end else if FracPart > 0 then begin if IntPart = 0 then rs := rs + DP[Fen + 1] + CrNa[3] else rs := rs + DP[1] + DP[Fen + 1] + CrNa[3]; end else begin rs := rs + CrNa[4]; end; if AValue = ‘0‘) and (Digits[i] 1e15) or (FloatValue 16 then rps := 16; beit := IntPower(10, rps); FraPart := Round(Frac(FloatValue) * beit); rs := LzhFmtInt(IntPart); if FraPart > 0 then begin Digits := IntToStr(FraPart); len := Length(Digits); while (len > 0) and (Digits[len] = ‘0‘) do len := len - 1; Digits := Copy(Digits, 1, len); rs := rs + DN[1] + LzhFmtDigits(Digits); end; if FloatValue < 0 then rs := DP[12] + rs; Result := rs;end;class function TCnDigits.LzhFmtInt(IntValue: Int64; IsYear: Boolean; SoftTone: Boolean):
String
;var i, n, t: Integer; bi: W
ide
String
; LastBt: W
ide
Char; rs: W
ide
String
; reach: Boolean; LastHit: Integer;begin //限制为18位数 if IntValue 8000000000000000000 then begin Result := ‘‘; Exit; end; bi := IntToStr(IntValue); //格式化为 bi :=
String
OfChar(‘0‘, 20 - Length(bi)) + bi; //从左侧开始格式化 LastBt := ‘ ‘; LastHit := 0; reach := False; for i := 1 to 20 do begin //如果非0 if (bi[i] >= ‘1‘) and (bi[i] <= ‘9‘) then begin //如果前一位是0,又不到分界位,补零 if reach and (LastBt = ‘0‘) and (i mod 4 1) then begin rs := rs + DP[1]; end; reach := True; //转换数字,如果是十位,且前一位为0 if SoftTone and (i mod 4 = 3) and (LastBt = ‘0‘) and ((not reach) or (bi[i] = ‘1‘)) then else begin rs := rs + DP[(Ord(bi[i]) - Ord(‘0‘)) mod 10 + 1]; end; //添加位名 n := (20 - i) mod 20 + 1; if n > 1 then begin rs := rs + DN[n]; end; LastHit := 20 - i; end; //分界名 if (bi[i] = ‘0‘) and (i mod 4 = 0) and reach then begin //特殊分界处的显示原则,8位前为空的不显示分界名 //不是8位处的,4位前为空不显示分界名 n := (20 - i) mod 20 + 1; t := n - 1; if (n > 1) and ( ((t mod 8 = 0) and (LastHit - t < 8)) or (((t - 12) mod 8 = 0) and (LastHit - t = 0 then if Result = ‘‘ then Result := FAlias.Values[Ws[i]] else Result := Result + ‘,‘ + FAlias.Values[Ws[i]] else if Result = ‘‘ then Result := Ws[i] else Result := Result + Ws[i]; end;end;function TCnDigits.StrToAlias2(S:
String
):
String
;var Ws: W
ide
String
; i: Integer; t: Integer;begin Ws := S; for i := 1 to Length(Ws) do begin t := T
String
List(FAlias).IndexOfName(Ws[i]); if t >= 0 then Result := Result + FAlias.Values[Ws[i]] else Result := Result + Ws[i]; end;end;constructor TCnDigits.Create(AOwner: TComponent);begin inherited; FAlias := T
String
List.Create; T
String
List(FAlias).Sorted := True; T
String
List(FAlias).Duplicates := dupIgnore;end;destructor TCnDigits.Destroy;begin FAlias.Free; inherited;end;procedure TCnDigits.SetDA(const Value: Boolean);var Ws: W
ide
String
; i: Integer; sv:
String
;begin if Value then begin Ws := DP + DN + CrNa + DtNa; for i := 1 to Length(Ws) do begin sv := Ws[i]; FAlias.Add(sv + ‘=‘ + FAlias.Values[Ws[i]]); end; end else begin for i := FAlias.Count - 1 downto 0 do begin sv := FAlias[i]; if Trim(sv) = ‘‘ then FAlias.Delete(i) else if (Length(sv) > 0) and (sv[Length(sv)] = ‘=‘) then FAlias.Delete(i); end; end; Fda := Value;end;procedure TCnDigits.SetCnUP(const Value:
String
);begin //FCnUpDigits := Value;end;class function TCnDigits.StdFmtDate(AValue: TDate; DigitsYear: Boolean):
String
;var yy, mm, dd: Word; ys: W
ide
String
; rs: W
ide
String
;begin DecodeDate(AValue, yy, mm, dd); if DigitsYear then ys := LzhFmtDigits(IntToStr(yy)) + DtNa[1] else ys := LzhFmtInt(yy, True) + DtNa[1]; rs := ys; if (mm <= 2) or (mm = 10) then rs := rs + DP[1]; rs := rs + LzhFmtInt(mm) + DtNa[2]; if (dd < 10) or (dd mod 10 = 0) then rs := rs + DP[1]; rs := rs + LzhFmtInt(dd) + DtNa[3]; Result := rs;end;class function TCnDigits.StdFmtDateTime(AValue: TDateTime; DigitsYear: Boolean):
String
;var dt: TDate; tm: TTime;begin dt := AValue; tm := AValue; Result := StdFmtDate(dt, DigitsYear) + LzhFmtTime(tm);end;end.附例子Demo
delphi通用函数单元一
//▎============================================================▎// //▎================① 扩展的字符串操作函数 ===================▎// //▎============================================================▎// //从文件中返回Ado连接字串。 function GetConnection
String
(DataBaseName:
string
):
string
; //返回服务器的机器名称. function GetRemoteServerName:
string
; function InStr(const sShort:
string
; const sLong:
string
): Boolean; {测试通过} {* 判断s1是否包含在s2中} function IntToStrEx(Value: Integer; Len: Integer; FillChar: Char = '0'):
string
; {测试通过} {* 扩展整数转字符串函数 Example: IntToStrEx(1,5,'0'); 返回:"00001"} function IntToStrSp(Value: Integer; SpLen: Integer = 3; Sp: Char = ','):
string
; {测试通过} {* 带分隔符的整数-字符转换} function ByteToBin(Value: Byte):
string
; {测试通过} {* 字节转二进制串} function StrRight(Str:
string
; Len: Integer):
string
; {测试通过} {* 返回字符串右边的字符 Examples: StrRight('ABCEDFG',3); 返回:'DFG' } function StrLeft(Str:
string
; Len: Integer):
string
; {测试通过} {* 返回字符串左边的字符} function Spc(Len: Integer):
string
; {测试通过} {* 返回空格串} function Replace(Str,s1,s2:
string
;CaseSensitive:Boolean):
string
; {测试通过} {* 返回将指定字符s1用字符串s2替换后的字符串,可支持大小写敏感由CaseSensitive操作} {example: replace('We know what we want','we','I',false) = 'I Know what I want'} function Replicate(pcChar:Char; piCount:integer):
string
; {在一个字符串中查找某个字符串的位置} function StrNum(ShortStr:
string
;Long
String
:
string
):Integer; {测试通过} {* 返回某个字符串中某个字符串中出现的次数} function FindStr(ShortStr:
String
;Long
StrIng
:
String
):Integer; {测试通过} {* 返回某个字符串中查找某个字符串的位置} function SubStr(psInput:
String
; BeginPlace,CutLeng:Integer):
String
; {测试通过} {* 返回从位置BeginPlace开始切取长度为CatLeng字符串} function LeftStr(psInput:
String
; CutLeng:Integer):
String
; {测试通过} {* 返回从左边第一为开始切取 CutLeng长度的字符串} function RightStr(psInput:
String
; CutLeng:Integer):
String
; {测试通过} {* 返回从右边第一为开始切取 CutLeng长度的字符串} function PadLStr(psInput:
String
; piWidth:Integer; pcPadWith:Char):
String
; {测试通过} {* 返回从psInput字符串左边开始用pcPadWith填充后总长度为PiWidth的字符串} function PadRStr(psInput:
String
; piWidth:Integer; pcPadWith:Char):
String
; {测试通过} {* 返回从psInput字符串右边开始用pcPadWith填充后总长度为PiWidth的字符串} function PadCStr(psInput:
String
; piWidth:Integer; pcPadWith:Char):
String
; {测试通过} {* 返回从psInput字符串两边开始用pcPadWith填充后总长度为PiWidth的字符串} function ChrTran(psInput:
String
; pcSearch:Char; pcTranWith:Char):
String
; {测试通过} {* 返回替换后字符串[替换单个字符] Examples: ChrTran('abCdEgdlkh','d','#'); 返回'abC#Eg#lkh'} function StrTran(psInput:
String
; psSearch:
String
; psTranWith:
String
):
String
; {测试通过} {* 返回替换后字符串[替换字符串] Examples: StrTran('aruyfbn','ruy','=====');; 返回'a=====fbn'} function Stuff(psInput:
String
; piBeginPlace,piCount:Integer; psStuffWith:
String
):
String
; { *返回替换后字符串[替换字符串] Examples: Stuff('ABCDEFGHI',3,4,'12345');返回'AB12345GHI'} procedure SwapStr(var s1, s2:
string
); {测试通过} {* 交换字串} function LinesToStr(const Lines:
string
):
string
; {测试通过} {* 多行文本转单行(换行符转'\n')} function StrToLines(const Str:
string
):
string
; {测试通过} {* 单行文本转多行('\n'转换行符)} function Encrypt(const S:
String
; Key: Word):
String
; {* 字符串加密函数} function Decrypt(const S:
String
; Key: Word):
String
; {* 字符串解密函数} function varIIF(aTest: Boolean; TrueValue, FalseValue: Variant): Variant; function varToStr(const V: Variant):
string
; {* VarIIF及VartoStr为变体函数} function IsDigital(Value:
string
): boolean; {功能说明:判断
string
是否全是数字} function RandomStr(aLength : Longint) :
String
; {随机字符串函数} //▎============================================================▎// //▎================② 扩展的日期时间操作函数 =================▎// //▎============================================================▎// function GetYear(Date: TDate): Integer; {测试通过} {* 取日期年份分量} function GetMonth(Date: TDate): Integer; {测试通过} {* 取日期月份分量} function GetDay(Date: TDate): Integer; {测试通过} {* 取日期天数分量} function GetHour(Time: TTime): Integer; {测试通过} {* 取时间小时分量} function GetMinute(Time: TTime): Integer; {测试通过} {* 取时间分钟分量} function GetSecond(Time: TTime): Integer; {测试通过} {* 取时间秒分量} function GetMSecond(Time: TTime): Integer; {测试通过} {* 取时间毫秒分量} function GetMonthLastDay(Cs_Year,Cs_Month:
string
):
string
; { *传入年、月,得到该月份最后一天} function IsLeapYear( nYear: Integer ): Boolean; {*/判断某年是否为闰年} function MaxDateTime(const Values: array of TDateTime): TDateTime; {//两个日期取较大的日期} function MinDateTime(const Values: array of TDateTime): TDateTime; {//两个日期取较小的日期} function dateBeginOfMonth(D: TDateTime): TDateTime; {//得到本月的第一天} function DateEndOfMonth(D: TDateTime): TDateTime; {//得到本月的最后一天} function DateEndOfYear(D: TDateTime): TDateTime; {//得到本年的最后一天} function DaysBetween(Date1, Date2: TDateTime): integer; {//得到两个日期相隔的天数} //▎============================================================▎// //▎===================③ 扩展的位操作函数 ====================▎// //▎============================================================▎// type TByteBit = 0..7; {* Byte类型位数范围} TWordBit = 0..15; {* Word类型位数范围} TDWordBit = 0..31; {* DWord类型位数范围} procedure SetBit(var Value: Byte; Bit: TByteBit; IsSet: Boolean); overload; {* 设置二进制位} procedure SetBit(var Value: WORD; Bit: TWordBit; IsSet: Boolean); overload; {* 设置二进制位} procedure SetBit(var Value: DWORD; Bit: TDWordBit; IsSet: Boolean); overload; {* 设置二进制位} function GetBit(Value: Byte; Bit: TByteBit): Boolean; overload; {* 取二进制位} function GetBit(Value: WORD; Bit: TWordBit): Boolean; overload; {* 取二进制位} function GetBit(Value: DWORD; Bit: TDWordBit): Boolean; overload; {* 取二进制位} //▎============================================================▎// //▎=================④扩展的文件及目录操作函数=================▎// //▎============================================================▎// function MoveFile(const sName, dName:
string
): Boolean; {测试通过} {* 移动文件、目录,参数为源、目标名} procedure FileProperties(const FName:
string
); {测试通过} {* 打开文件属性窗口} function CreatePath(path :
string
) : Boolean; function OpenDialog(var FileName:
string
; Title:
string
; Filter:
string
; Ext:
string
): Boolean; {* 打开文件框} function FormatPath(APath:
string
; Width: Integer):
string
; {测试通过} {* 缩短显示不下的长路径名} function GetRelativePath(Source, Dest:
string
):
string
; {测试通过} {* 取两个目录的相对路径,注意串尾不能是'\'字符!} procedure RunFile(const FName:
string
; Handle: THandle = 0; const Param:
string
= ''); {测试通过} {* 运行一个文件} function WinExecAndWait32(FileName:
string
; Visibility: Integer = SW_NORMAL): Integer; {测试通过} {* 运行一个文件并等待其结束} function AppPath:
string
; {测试通过} {* 应用程序路径} function GetDiskInfo(sFile :
string
; var nDiskFree,nDiskSize : Int64): boolean; {测试通过} {* 取sFile 所在磁盘空间状态 } function GetWindowsDir:
string
; {测试通过} {* 取Windows系统目录} function GetWinTempDir:
string
; {测试通过} {* 取临时文件目录} function AddDirSuffix(Dir:
string
):
string
; {测试通过} {* 目录尾加'\'修正} function MakePath(Dir:
string
):
string
; {测试通过} {* 目录尾加'\'修正} function IsFileInUse(FName:
string
): Boolean; {测试通过} {* 判断文件是否正在使用} function GetFileSize(FileName:
string
): Integer; {测试通过} {* 取文件长度} function SetFileDate(FileName:
string
; CreationTime, LastWriteTime, LastAccessTime: TFileTime): Boolean; {测试通过} {* 设置文件时间 Example: FileSetDate('c:\Test\Test1.exe',753160662); } function GetFileDate(FileName:
string
; var CreationTime, LastWriteTime, LastAccessTime: TFileTime): Boolean; {测试通过} {* 取文件时间} function FileTimeToLocalSystemTime(FTime: TFileTime): TSystemTime; {测试通过} {* 文件时间转本地时间} function LocalSystemTimeToFileTime(STime: TSystemTime): TFileTime; {测试通过} {* 本地时间转文件时间} function GetFileIcon(FileName:
string
; var Icon: TIcon): Boolean; {测试通过} {* 取得与文件相关的图标,成功则返回True} function CreateBakFile(FileName, Ext:
string
): Boolean; {测试通过} {* 创建备份文件} function Deltree(Dir:
string
): Boolean; {测试通过} {* 删除整个目录} function GetDirFiles(Dir:
string
): Integer; {测试通过} {* 取文件夹文件数} type TFindCallBack = procedure(const FileName:
string
; const Info: TSearchRec; var Abort: Boolean); {* 查找指定目录下文件的回调函数} procedure FindFile(const Path:
string
; const FileName:
string
= '*.*'; Proc: TFindCallBack = nil; bSub: Boolean = True; const bMsg: Boolean = True); {* 查找指定目录下文件} procedure FindFileList(Path:
string
;Filter,FileList:T
String
s;ContainSubDir:Boolean; lb: TLabel=nil); { 功能说明:查找一个路径下的所有文件。 参数: path:路径,filter:文件扩展名过滤,FileList:文件列表, ContainSubDir:是否包含子目录} function Txtline(const txt:
string
): integer; {* 返回一文本文件的行数} function Html2Txt(htmlfilename:
string
):
string
; {* Html文件转化成文本文件} function OpenWith(const FileName:
string
): Integer; {测试通过} {* 文件打开方式} //▎============================================================▎// //▎====================⑤扩展的对话框函数======================▎// //▎============================================================▎// procedure InfoDlg(Mess:
string
; Caption:
string
= SCnInformation; Flags: Integer = MB_OK + MB_ICONINFORMATION); {测试通过} {* 显示提示窗口} function InfoOk(Mess:
string
; Caption:
string
= SCnInformation): Boolean; {测试通过} {* 显示提示确认窗口} procedure ErrorDlg(Mess:
string
; Caption:
string
= SCnError); {测试通过} {* 显示错误窗口} procedure WarningDlg(Mess:
string
; Caption:
string
= SCnWarning); {测试通过} {* 显示警告窗口} function QueryDlg(Mess:
string
; Caption:
string
= SCnInformation): Boolean; {测试通过} {* 显示查询是否窗口} procedure SetWindowAnimate(Sender : TForm; IsSetAni : bool); //▎============================================================▎// //▎=====================⑥系统功能函数=========================▎// //▎============================================================▎// procedure MoveMouseIntoControl(AWinControl: TControl); {测试通过} {* 移动鼠标到控件} function DynamicResolution(x, y: WORD): Boolean; {测试通过} {* 动态设置分辨率} procedure StayOnTop(Handle: HWND; OnTop: Boolean); {测试通过} {* 窗口最上方显示} procedure SetHidden(H
ide
: Boolean); {测试通过} {* 设置程序是否出现在任务栏} procedure SetTaskBarVisible(Visible: Boolean); {测试通过} {* 设置任务栏是否可见} procedure SetDesktopVisible(Visible: Boolean); {测试通过} {* 设置桌面是否可见} procedure BeginWait; {测试通过} {* 显示等待光标} procedure EndWait; {测试通过} {* 结束等待光标} function CheckWindows9598NT:
string
; {测试通过} {* 检测是否Win95/98/NT平台} function GetOSInfo :
String
; {测试通过} {* 取得当前操作平台是 Windows 95/98 还是NT} function GetCurrentUserName :
string
; {*获取当前Windows登录名的用户} function GetRegistryOrg_User(UserKeyType:
string
):
string
; {*获取当前注册的单位及用户名称} function GetSysVersion:
string
; {*//获取操作系统版本号} function WinBootMode:
string
; {//Windows启动模式} type PShutType = (UPowerOff, UShutdown, UReboot, ULogOff, USuspend, UHibernate); procedure WinShutDown(ShutWinType:PShutType; PForce:Boolean); {//Windows ShutDown等} //▎============================================================▎// //▎=====================⑦硬件功能函数=========================▎// //▎============================================================▎// function GetClientGUID:
string
; { 功能描述:在本机上得到一个GUID.去掉两端的大括号和中间的横线 返回值:去掉两端的大括号和中间的横线的一个GUID 适用范围:windows } function SoundCardExist: Boolean; {测试通过} {* 声卡是否存在} function GetDiskSerial(DiskChar: Char):
string
; {* 获取磁盘序列号} function DiskReady(Root:
string
) : Boolean; {*检查磁盘准备是否就绪} procedure WritePortB( wPort : Word; bValue : Byte ); {* 写串口} function ReadPortB( wPort : Word ) : Byte; {*读串口} function CPUSpeed: Double; {* 获知当前机器CPU的速率(MHz)} type TCPUID = array[1..4] of Longint; function GetCPUID : TCPUID; assembler; register; {*获取CPU的标识ID号*} function GetMemoryTotalPhys : Dword; {*获取计算机的物理内存} type TDriveState = (DSNODISK, DSUNFORMATTEDDISK, DSEMPTYDISK, DSDISK_WITHFILES); function DriveState (driveletter: Char) : TDriveState; {* 检查驱动器A中磁盘是否有效} //▎============================================================▎// //▎=====================⑧网络功能函数=========================▎// //▎============================================================▎// function GetComputerName:
string
; {* 获取网络计算机名称} function GetHostIP:
string
; {* 获取计算机的IP地址} function NetUserChangePassword(Domain:PW
ide
Char; UserName:PW
ide
Char; OldPassword:PW
ide
Char; NewPassword:PW
ide
Char): LongInt; stdcall; external 'netapi32.dll' name 'NetUserChangePassword'; {* // 运行平台:Windows NT/2000/XP {* // Windows 95/98/Me平台:可以用该函数修改用户的Windows登录密码} //▎============================================================▎// //▎=====================⑨汉字拼音功能函数=====================▎// //▎============================================================▎// function GetHzPy(const AHzStr:
string
):
string
; {测试通过} {* 取汉字的拼音} function HowManyChineseChar(Const s:
String
):Integer; {* 判断一个字符串中有多少各汉字} //▎============================================================▎// //▎===================⑩数据库功能函数及过程===================▎// //▎============================================================▎// {function PackDbDbf(Var StatusMsg:
String
): Boolean;} {* 物理删除数据库(Db,Dbf)中的数据[着了删除标记的记录]} procedure RepairDb(DbName:
string
); {* 修复Access表} function CreateODBCCfgInRegistry(ODBCSourceName:W
ide
String
;ServerName, DataBaseDescription:
String
):boolean; {* 通过注册表创建ODBC配置[创建在系统DSN页下]} function ADOConnectSysBase(Const Adocon:TadoConnection):boolean; {* 用Ado连接SysBase数据库函数} function ADOConnectLocalDB(Const Adocon:TadoConnection;Const Dbname,DbServerName:
string
;ValidateMode:Integer):boolean; {* 用Ado连接数据库函数} function ADOODBCConnectLocalDB(Const Adocon:TadoConnection;Const Dbname:
string
;ValidateMode:Integer):boolean; {* 用Ado与ODBC共同连接数据库函数} function CreatTable(LpDataBaseName,LpTableName,LpSentence:
string
):Boolean; {* //建立新表} function AddField(LpFieldName:
string
; LpDataType: TFieldType; LpSize: Word):
string
; {*//在表中添加字段} function KillField(LpFieldName:
string
):
String
; {* //在表中删除字段} function AlterTableExec(LpDataBaseName,LpSentence:
string
):Boolean; {* //修改表结构} function GetSQLSentence(LpTableName,LpSQLsentence:
string
):
string
; {* /修改、添加、删除表结构时的SQL句体} //▎============================================================▎// //▎======================⑾进制函数及过程======================▎// //▎============================================================▎// function StrToHex(AStr:
string
):
string
; {* 字符转化成十六进制} function HexToStr(AStr:
string
):
string
; {* 十六进制转化成字符} function TransChar(AChar: Char): Integer; //▎============================================================▎// //▎=====================⑿其它函数及过程=======================▎// //▎============================================================▎// function TrimInt(Value, Min, Max: Integer): Integer; overload; {测试通过} {* 输出限制在Min..Max之间} function IntToByte(Value: Integer): Byte; overload; {测试通过} {* 输出限制在0..255之间} function InBound(Value: Integer; Min, Max: Integer): Boolean; {测试通过} {* 判断整数Value是否在Min和Max之间} procedure CnSwap(var A, B: Byte); overload; {* 交换两个数} procedure CnSwap(var A, B: Integer); overload; {* 交换两个数} procedure CnSwap(var A, B: Single); overload; {* 交换两个数} procedure CnSwap(var A, B: Double); overload; {* 交换两个数} function RectEqu(Rect1, Rect2: TRect): Boolean; {* 比较两个Rect是否相等} procedure DeRect(Rect: TRect; var x, y, Width, Height: Integer); {* 分解一个TRect为左上角坐标x, y和宽度Width、高度Height} function EnSize(cx, cy: Integer): TSize; {* 返回一个TSize类型} function RectWidth(Rect: TRect): Integer; {* 计算TRect的宽度} function RectHeight(Rect: TRect): Integer; {* 计算TRect的高度} procedure Delay(const uDelay: DWORD); {测试通过} {* 延时} procedure BeepEx(const Freq: WORD = 1200; const Delay: WORD = 1); {Win9X下测试通过} {* 只能在Win9X下让喇叭发声} procedure ShowLastError; {测试通过} {* 显示Win32 Api运行结果信息} function writeFontStyle(FS: TFontStyles; inifile:
string
; write: boolean):
string
; {* 将字体Font.Style写入INI文件} function readFontStyle(inifile:
string
): TFontStyles; {* 从INI文件中读取字体Font.Style文件} //function ReadCursorPos(SourceMemo: TMemo): TPoint; function ReadCursorPos(SourceMemo: TMemo):
string
; {* 取得TMemo 控件当前光标的行和列信息到Tpoint中} function CanUndo(AMemo: TMemo): Boolean; {* 检查Tmemo控件能否Undo} procedure Undo(Amemo: Tmemo); {*实现Undo功能} procedure AutoListDisplay(ACombox:TComboBox); {* 实现ComBoBox自动下拉} function UpperMoney(small:real):
string
; {* 小写金额转换为大写 } function Myrandom(Num: Integer): integer; {*利用系统时间产生随机数)} procedure OpenIME(ImeName:
string
); {*打开输入法} procedure CloseIME; {*关闭输入法} procedure ToChinese(hWindows: THandle; bChinese: boolean); {*打开中文输入法} //数据备份 procedure BackUpData(LpBackDispMessTitle:
String
); procedure ImageLoadGif(Picture: TPicture; filename:
string
); procedure ImageLoadJpg(Picture: TPicture; filename:
string
);
Delphi中T
string
s类型的用法与实例
Delphi中T
string
s类型的用法与实例 (2012-08-22 16:22:59)转载▼标签: 例子 分隔符 字符串 数据类型 抽象类 t
string
t
string
list delphi it 分类: deph
ide
lphi中的T
string
List类型procedure TForm1.Button2Click(Sender: TObject);varts: T
String
List;i:...
DelphiXE10
String
、ANSI
String
及TBytes之间的转换
DelphiXE10中
String
、ANSI
String
及TBytes之间的转换
将字符串
转换成
UTF8 编码的函数
这种转换一般用于网页地址; 我不知道 Delphi 是不是有现成的函数, 用到了就写了一个. //函数: function ToUTF8Encode(str:
string
):
string
; var b: Byte; begin for b in BytesOf(UTF8Encode(str)) do Result := Format('%s%%%.2x...
C++ Builder
13,825
社区成员
102,679
社区内容
发帖
与我相关
我的任务
C++ Builder
C++ Builder相关内容讨论区
复制链接
扫一扫
分享
社区描述
C++ Builder相关内容讨论区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章