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

📄 parseexpression.pas

📁 财务软件:功能尚可,基于UML设计开发的delphi系统,文档齐全
💻 PAS
字号:
unit ParseExpression;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs;

type
  TParseExpression = class(TObject)
  private
    FExpression: string;
    FStringList: TStringList;
  public
    function GetBeginEndCode(vS,vE:String): string;
    function GetCode: string;
    function GetFuncName: string;
    function GetPara(vExpression,vS,vE:String): string;
    function GetPeriod: Integer;
    function GetYear: Integer;
    function Splite(Src,Dec:String): TStringList;
  published
    property Expression: string read FExpression write FExpression;
  end;
  

implementation

{
******************************* TParseExpression *******************************
}
function TParseExpression.GetBeginEndCode(vS,vE:String): string;
var
  BeginCode, EndCode, i: Integer;
begin
  BeginCode:=StrToInt(vS);
  EndCode:=StrToInt(vE);
  for i:=BeginCode to EndCode-1 do
      Result:=Result+IntToStr(i)+',';
  Result:=Result+IntToStr(EndCode);
end;

function TParseExpression.GetCode: string;
var
  tmpStr, BeginCode, EndCode: string;
  i, j: Integer;
  CodeList, tmpList: TStringList;
begin
  CodeList:=TStringlist.Create;
  tmpStr:=GetPara(FExpression,'<CODE>','</CODE>');
  tmpList:=Splite(tmpStr,',');
  //如果含有:,即起止范围界定符,则继续处理
  for i:=0 to tmpList.Count-1 do
      {//不处理,交与服务器处理
      //如果是:
      if Pos(':',tmpList.Strings[i])>0 then
      begin
        //取起止
        with Splite(tmpStr,':') do
        begin
          BeginCode:=Strings[0];
          EndCode:=Strings[1];
        end;
        //拆分
        with Splite(GetBeginEndCode(BeginCode,EndCode),',') do
           for j:=0 to Count-1 do CodeList.Add(Strings[j]);
      end
      else
      }    CodeList.Add(tmpList.Strings[i]);
  
  tmpStr:='';
  
  i:=0;
  if CodeList.Count>=2 then
     for i:=0 to CodeList.Count-2 do
         tmpStr:=tmpStr+CodeList.Strings[i]+',';
  if CodeList.Count>0 then
     tmpStr:=tmpStr+CodeList.Strings[i];
  Result:=tmpStr;
end;

function TParseExpression.GetFuncName: string;
begin
  Result:=Uppercase(GetPara(FExpression,'<FUNCTION>','</FUNCTION>'));
end;

function TParseExpression.GetPara(vExpression,vS,vE:String): string;
var
  Site1, Site2: Integer;
  tmpStr: string;
begin
  //返回界定符之间的字符串
  vS:=Uppercase(vS);
  vE:=Uppercase(vE);
  Site1:=Pos(vS,vExpression);
  Site2:=Pos(vE,vExpression);
  Result:=Copy(vExpression,Site1+length(vS),Site2-Site1-length(vS));
end;

function TParseExpression.GetPeriod: Integer;
var
  tmpStr: string;
begin
  tmpStr:=GetPara(FExpression,'<PERIOD>','</PERIOD>');
  Result:=strtoint(tmpStr);
end;

function TParseExpression.GetYear: Integer;
var
  tmpStr: string;
begin
  tmpStr:=GetPara(FExpression,'<YEAR>','</YEAR>');
  Result:=strtoint(tmpStr);
end;

function TParseExpression.Splite(Src,Dec:String): TStringList;
var
  I: Integer;
  str: string;
begin
  result := TStringList.Create;
  repeat
    i := pos(dec,src);
    str := copy(src,1,i-1);
    if (str='') and (i>0) then
    begin
      delete(src,1,length(dec));
      result.Add(src);
      continue;
    end;
    if i>0 then
    begin
      result.Add(str);
      delete(src,1,i+length(dec)-1);
    end;
  until i<=0;
  if src<>'' then
    result.Add(src);
end;


end.

⌨️ 快捷键说明

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