⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ustring.pas

📁 这是一个啤酒行业的软件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit uString;

interface
uses
    Variants,
    Messages,
    Dialogs,
    Windows,
    StdCtrls,
    ComCtrls,
    Classes,
    StrUtils,
    Math,
    Forms,
    graphics,
    SysUtils;

Type
    TactionType = (aT_save,aT_delete,aT_update);
    TuString=class

    private
         Function NumberCn(mNumber: Real): WideString;
         Function  CreateRegion(wMask:TBitmap;wColor:TColor;hControl:THandle):HRGN;
    public
         Function getSubStringCount(substring:String;str:String):integer;
         Function right(sourceString:string;iCount:integer):string;
         Function left(sourceString:string;iCount:integer):string;
         Function replace(sub1:string;sub2:string;source:string):string;
         Function formatString(source:Variant;pointCount:integer):string;
         Function formatDate(dateType:integer):string;overload;
         Function formatDate(_date:Variant;dateType:integer):string;overload;
         Function isValidateNumber(sourceStr:string;Dec:boolean):boolean;
         Function isValidateDate(sourceStr:string):boolean;
         Function getSubFirstPos(substring:string;sourceString:string;iCount:integer):integer;

         Function saveMessage:boolean;
         Function deleteMessage:boolean;
         Function updateMessage:boolean;

         procedure actionOK(actionType:TactionType);

          /////将小写金额转化为大写金额////////////////////////////////////////
         Function MoneyToCn(mMoney: Real): WideString;
         
         Procedure ShowPloyForm(Bmp:TBitmap;hControl:THandle);
    protected

    published

end;

implementation
{
  功能: 返回要查询的子串在总字符串中出现的次数
  参数:
        substring:要查询的子串
        str:总字符串
  用法: getSubstringCount(':','aaa=:a and  bbb=:b')
        返回':'在字符串'aaa=:a and  bbb=:b'中出现的次数
}
Function TuString.getSubStringCount(substring:string;str:string):integer;
var
   _a:TStringList;
   i:integer;
   _Substr:string;
begin
   _a:=TStringList.Create;
   _a.Clear;
   try

       _Substr:=trim(str);
       i:=0;
       while  pos(substring,_Substr)>0 do
       begin
              inc(i);
              delete(_Substr,1,pos(substring,_Substr));
              _a.Add(inttostr(i))
       end;//i
       result:=_a.Count;
   Finally
       _a.Free;
   end;
end;
{
    功能:从右边截取指定数量的字符
    参数:
         sourceString:原字符串
         iCount:要截取的字符串数量
    用法:right('asddfffgg',5)
         从右边截取5个字符串
}
Function TuString.right(sourceString:string;iCount:integer):string;
begin
     result:=StrUtils.RightStr(sourceString,iCount);
end;
{
    功能:从左边截取指定数量的字符
    参数:
         sourceString:原字符串
         iCount:要截取的字符串数量
    用法:left('asddfffgg',5)
         从左边截取5个字符串
}
Function TuString.left(sourceString:string;iCount:integer):string;
begin
     result:=StrUtils.leftStr(sourceString,iCount);
end;
{
    功能: 在source中用sub2替换sub1
    参数:
          sub1:子串1
          sub2:子串2
          source:原字符串

    用法: replace('aa','bb','aaggffaa')
          字符串'aaggffaa'中的'aa'用'bb'代替
}
Function TuString.replace(sub1:string;sub2:string;source:string):string;
var
    _length:integer;
begin
    while pos(sub1,source)>0 do
    begin
          _length:=length(sub1);
          delete(source,pos(sub1,source),_length);
          insert(sub2,source,pos(sub1,source));
    end;
    result:=source;
end;
{
    功能:格式化输出数值
    参数:
         source:原数值,可以是字符串,整形,浮点
         pointCount:小数点个数
    用法:formatString('123.45',0)输出'123'
         formatString(123.45,0) 
}
Function TuString.formatString(source:Variant;pointCount:integer):string;
var
    _result:string;
begin
    if pointCount=0 then
    begin
       _result:=formatFloat('#00',strToFloat(VartoStr(source)));
    end;
    if pointCount=1 then
    begin
       _result:=formatFloat('#00.0',strToFloat(VartoStr(source)));
    end;
    if pointCount=2 then
    begin
       _result:=formatFloat('#00.00',strToFloat(VartoStr(source)));
    end;
    if pointCount=3 then
    begin
       _result:=formatFloat('#00.000',strToFloat(VartoStr(source)));
    end;
    if pointCount=4 then
    begin
       _result:=formatFloat('#00.0000',strToFloat(VartoStr(source)));
    end;
    if pointCount=5 then
    begin
       _result:=formatFloat('#00.00000',strToFloat(VartoStr(source)));
    end;
    result:=_result;
end;
{
    功能:返回指定格式的日期
    参数:dateType:日期类型
    用法:
}
Function TuString.formatDate(dateType:integer):string;
begin
    if dateType=1 then
    begin
       result:=formatdatetime('yyyy年mm月dd日',now);
    end;
    if dateType=2 then
    begin
       result:=formatdatetime('yyyy-mm-dd',now);
    end;
    if dateType=3 then
    begin
       result:=formatdatetime('yyyy.mm.dd',now);
    end;
    if dateType=4 then
    begin
       result:=formatdatetime('mm/dd/yyyy',now);
    end;
    if dateType=5 then
    begin
       result:=formatdatetime('yyyy-mm-dd hh:mm:ss',now);
    end;
end;
{
    功能:返回指定格式的日期
    参数:dateType:日期格式类型
         _date:日期
    用法:
}
Function TuString.formatDate(_date:Variant;dateType:integer):string;
begin
    if dateType=1 then
    begin
       result:=formatdatetime('yyyy年mm月dd日',StrtoDate(trim(VarToStr(_date))));
    end;
    if dateType=2 then
    begin
       result:=formatdatetime('yyyy-mm-dd',now);
    end;
    if dateType=3 then
    begin
       result:=formatdatetime('yyyy.mm.dd',now);
    end;
    if dateType=4 then
    begin
       result:=formatdatetime('mm/dd/yyyy',now);
    end;
    if dateType=5 then
    begin
       result:=formatdatetime('yyyy-mm-dd hh:mm:ss',now);
    end;
end;
{
    功能:判断是否为有效的数值
    参数:sourceStr:要输入的字符串
          Dec:是否带小数点
    用法:
}
Function TuString.isValidateNumber(sourceStr:string;Dec:boolean):boolean;
var
   a:integer;
   s:string;
begin
   s:=trim(sourceStr);
   result:=true;
   for a:=1 to length(s) do
   begin
       if (Dec) then
       begin
          if not (s[a] In ['0'..'9','.']) then
          begin
             result:=false;
             exit;
          end;//if not
       end//if else dec
       else
       begin
          if not (s[a] In ['0'..'9']) then
          begin
             result:=false;
             exit;
          end;//if not
       end;//if Dec
   end;//for
end;
{
    功能: 返回子串在总串中第几次出现的位置//////////////
    参数: substring:子串
          sourceString:原字符串
          iCount:第几次
    用法:
}
Function TuString.getSubFirstPos(substring:string;sourceString:string;iCount:integer):integer;
var
   sub:string;
   s:string;
   i:integer;
   _Count:integer;
begin
   sub:=trim(substring);
   s:=trim(sourceString);
   _Count:=0;
   for i:=1 to iCount do
   begin
       if pos(sub,s)>0 then
       begin
          _Count:=_Count+pos(sub,s);
          delete(s,1,pos(sub,s));
       end;//if pos
   end;//for
   result:=_Count;
end;
{
    功能: 判断是否为有效的日期格式
    参数:
         yyyy-mm-dd
         yyyy/mm/dd
         yy/m/d
         yy-mm-dd
    用法:
}
Function TuString.isValidateDate(sourceStr:string):boolean;
var
   s:string;
   se:string;
   _firstPos,_firstPos1,_firstPos2:integer;
   _secondPos,_secondPos1,_secondPos2:integer;
   _year,_month,_day:string;
   _year1,_month1,_day1:string;
   _year2,_month2,_day2:string;
   ////增加一种情况即:yyyy年mm月dd日
   _YearPos:integer;///年位置
   _MonthPos:integer;///月位置
   _dayPos:integer;////日位置
   _Len:integer;////字符串总长度
begin
   s:=trim(sourceStr);
   /////对于分割符'-'的//////
   _firstPos:=getSubFirstPos('-',s,1);
   _secondPos:=getSubFirstPos('-',s,2);
   _year:=copy(s,1,_firstPos-1);///年
   _month:=copy(s,_firstPos+1,_secondPos-_firstPos-1);//月
   _day:=copy(s,_secondPos+1,length(s)-_secondPos);///日
   result:=true;
   if (getSubstringCount('-',s)=2) then
   begin
      ///yyyy-mm-dd格式/////////
      if (length(trim(_year))=4) and (length(trim(_month))=2)  and  (length(trim(_day))=2) then
      begin
         if (isValidateNumber(_year,false)) and (isValidateNumber(_month,false)) and  (isValidateNumber(_day,false)) then
         begin
            result:=true;
         end
         else
            result:=false;
      end//if
      else
         result:=false;
      ///yy-mm-dd格式/////////
      if (length(trim(_year))=2) and (length(trim(_month))=2)  and  (length(trim(_day))=2) then
      begin
         if (isValidateNumber(_year,false)) and (isValidateNumber(_month,false)) and  (isValidateNumber(_day,false)) then
         begin
            result:=true;
         end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -