我的编者是
TG20040828000
结构是TG+年月日+三位数有一很奇怪的是
从TG20040828001自动加到TG20040828009都没有问题,但是想加到10时就变为
TG200408280010,而我要的是TG20040828010
代码如下:
  
s:='TG'+formatdatetime('yyyymmdd',now());
  with adoquery1 do
   begin
      close;
      SQL.Clear;
      sql.add('select max(订单id) as ss from 订单');
      open;
  end;
  //自动生成编号
  if adoquery1.FieldByName('ss').Value=null then
     s:=s+'001'
  else
    begin
      m:=trim(adoquery1.fieldbyname('ss').value);
      i:=strtoint(trim(copy(m,11,5)));
      if i<10 then
          s:=s+'00'+inttostr(i+1)
       else if i<100 then
          s:=s+'0'+inttostr(i+1)
       else
          s:=s+inttostr(i+1);
       end;

解决方案 »

  1.   

    晕,当i=9的时候执行的是s:=s+'00'+inttostr(i+1)
    当然就变成了0010
      

  2.   

    i<9; i<99
    这样改应该就没问题了
      

  3.   

    if adoquery1.FieldByName('ss').Value=null then
      s:=s+'001'
    else
    begin
      m:=trim(adoquery1.fieldbyname('ss').value);
      i:=strtoint(trim(copy(m,11,5)));
      if i<9 then
        s:=s+'00'+inttostr(i+1)
      else if i<99 then
        s:=s+'0'+inttostr(i+1)
      else
        s:=s+inttostr(i+1);
    end;
      

  4.   

    i:=strtoint(trim(copy(m,11,5)));
    改成
    i:=strtoint(trim(copy(m,11,5)))+1;
    也行
      

  5.   

    //自动生成编号
      if adoquery1.FieldByName('ss').Value=null then
        s:=s+'001'
      else
        begin
          m:=trim(adoquery1.fieldbyname('ss').value);
          i:=strtoint(trim(copy(m,11,5)));
          s:=s+FormatFloat('0###',i+1);
        end;
      

  6.   

    改正
    //自动生成编号
      if adoquery1.FieldByName('ss').Value=null then
        s:=s+'001'
      else
        begin
          m:=trim(adoquery1.fieldbyname('ss').value);
          i:=strtoint(trim(copy(m,11,5)));
          s:=s+RightStr(FormatFloat('0###',i+1),3);
        end;
      

  7.   

    采用字符串截取法(一年前用过)
    前几位不说就当已经生成了只说最后三位:
    m:=copy(m,1,length(m)-lengtth(inttostr(inc(strtoint(copy(m,length(m)-3,3))))))+
    inttostr(inc(strtoint(copy(m,length(m)-3,3))))
    直接写的,你自己看着用吧~
      

  8.   

    刚才少加了个‘1’可能会不对你再试这个:  
     m:=copy(m,1,length(m)-lengtth(inttostr(inc(strtoint(copy(m,length(m)-3+1,3))))))+
    inttostr(inc(strtoint(copy(m,length(m)-3+1,3))))自动增加