在每次保存事件触发的时候计算出一下个编号的值
Function ADO_AddStringID(ConnectionName:TADOConnection;TblName,IDFldName:String;StringIDLength:Word):String;
var
strID:String;
LastID:String;
tblInsert:TAdoTable;
begin
tblInsert:=TAdoTable.Create(nil);
with tblInsert do
try
if Active then Close;
Connection:=ConnectionName;
TableName:=TblName;
Open;
with tblInsert do
begin
last;
if FieldByName(IDFldName).AsString<>'' then
LastID:=FieldByName(IDFldName).AsString
else
LastID:='0';
end;
strID:=AddZeroToString(StrInc(LastID),StringIDLength);
Close;
finally
Free;
end;
Result:=strID;
end;
第次事件触发的时候
If MessageBox(handle,'是否确定要添加资料!','提示',68+MB_DEFBUTTON2)=6 then
begin
StrID:=Ado_AddStringID(Ado_Data.ADOConnection1,'ProduceData','ID',8);
If Check then
begin
If Insert_Data(StrID) then //这是添加的一个函数,成功返回True 出错返回False
begin
MessageBox(handle,'添加成功!','提示',64);
Form_Document.Data_Refresh('Select * from ProduceData Where IsDele=0 and SeeNo=0 and FormType='+IntToStr(TypeIndex),StrID);
Close;
end
else
begin
MessageBox(handle,'添加失败,请重试!','提示',64);
end;
end;
end;