我有个edit,我想让他自动产生数据为SP+日期+0001的数据,形如SG-2006-02-18-0001,点击button1后产生了,SG-2006-02-18-0002,再点一下产生SG-2006-02-18-0003,要怎样才能得到这些自动加1的数据?这点不明白,请教各位大虾!

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i: integer;
    function MyFormat(i: integer): string;
    begin
      if i<0 then
        Result := '0000'
      else if i<10 then
        Result := '000' + IntToStr(i)
      else if i<100 then
        Result := '00' + IntToStr(i)
      else if i<1000 then
        Result := '0' + IntToStr(i)
      else if i<10000 then
        Result := IntToStr(i)
      else
        Result := '9999';
    end;
    begin
      i := StrToInt(Copy(Edit1.Text, Length(Edit1.Text)-3, 4))+1;
      Edit1.Text := Copy(Edit1.Text, 1, Length(Edit1.Text)-4) + MyFormat(i);
    end;
      

  2.   

    楼上的:我编译时产生如下错误信息:
      Project project1.exe raised exception class EConvertError with message ''' is not a valid integer value'.Process stopped.
    这是怎么回事啊!
      

  3.   

    我想生成当天的日期,比如今天是21号,那么会动态产生SG-2006-02-21-0001,然后点击则生成SG-2006-02-21-0001,再点击生成SG-2006-02-21-0002。我的目的是想动态生成“SG-当天日期-自动加1”的格式。
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Edit1.Text:=Copy(Edit1.Text,1,Length(Edit1.Text)-4)+Format('%.4d',[StrToInt(Copy(Edit1.Text,Length(Edit1.Text)-3,4))+1]);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Edit1.Text:='SG-'+FormatDateTime('yyyy-mm-dd',now)+'-0001'
    end;
      

  5.   

    一个全局Integer变量n,初始为0
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Inc(n);
      Edit1.Text := 'SG-' + FormatDateTime('yyyy-mm-dd-', Date) + FormatFloat('0000', n);
    end;