主题:用Delphi编写一个自动生成编号!!
以下这个程序编写出来之后用第一次可以,但第二次用时也就是当数据库中有一条记录时会出错,不是我想要的结果,请高手加以指点!!
procedure TForm1.BitBtn1Click(Sender: TObject);
var
s,m: String;
i: integer;
begin
s:= 'PH'+ FormatDateTime('yyyymmdd',Now());
With Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select max(bh) as ss From hwmc ');
Open;
end;
If Query1.FieldByName('ss').Value = null then
s := s + '001'
else
begin
m:= Trim(Query1.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;
Label7.Caption := s;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
s,m: String;
i: integer;
begin
s:= 'PH'+ FormatDateTime('yyyymmdd',Now());
With Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select max(bh) as ss From hwmc ');
Open;
end;
If Query1.FieldByName('ss').Value = null then
s := s + '001'
else
begin
m:= Trim(Query1.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;
Label7.Caption := s;
end;