我没改动的时侯没有进行commit也行,改动后加了commit也不行 怀疑是query没有正常释放,程序在运行几次后就不能再运行了,说内存不足 代码写的很烂:procedure TFrm_DJWH_CHDWH.BTN_AddNoClick(Sender: TObject); var _KHBH:string; _No:integer; begin //判断返回结果集不为空时(即存在现有单号),客户编号是否为空 if (not DM.Query_CHDWH.IsEmpty) and ((LKCBB_KHBH.Text=' ') or (LKCBB_KHBH.Text='')) then begin MessageDlg('客户编号不能为空,请选择客户编号!',mtInformation,[mbOK],0); exit; end; with DM.Query_CHDWH do begin //判断单号是否为空,即判断是否为新增单号 if IsEmpty or (RecordCount<1) then begin //Get_TempBill过程生成临时单号 Get_TempBill; Temp_Bill:=_DH; DM.Query_Temp.Close; //得到初始序号 _No:=1; //客户编号不能为空,所以赋值为空格 _KHBH:=' '; Close; SQL.Clear; SQL.Add('Select * from billaffirm where Ba_billnum='''+_DH+''' order by Ba_no'); RequestLive:=true; Open; end else begin //从第一条到最后一条记录进行逐行检查 First; while not Eof do begin if FieldByName('Ba_cmcode').AsString='' then begin MessageDlg('客户编号不能为空',mtInformation,[mbOK],0); LKCBB_KHBH.SetFocus; Exit; end; if FieldByName('Ba_Pdcode1').AsString='' then begin MessageDlg('产品编号不能为空',mtInformation,[mbOK],0); Exit; end; if (FieldByName('Ba_PdNum').AsString='') or (FieldByName('Ba_PdNum').AsInteger=0) then begin MessageDlg('产品数量不能为空',mtInformation,[mbOK],0); Exit; end; Next; end; // end while _DH:=FieldByName('Ba_billnum').AsString; //这里得到单号的最大序号 Last; _No:=FieldByName('Ba_no').AsInteger+1; _KHBH:=FieldByName('Ba_cmcode').AsString; end;// end if else Insert; Edit; //以下字段均不允许为空,所以要赋默认值 //单号 FieldByName('Ba_billnum').AsString:=_DH; //序号 FieldByName('Ba_no').AsInteger:=_No;... ...//客户编号 FieldByName('Ba_cmcode').AsString:=_KHBH; //制单时间 FieldByName('Ba_maketime').AsDateTime:=now; Post; ApplyUpdates; Close; RequestLive:=true; Open; Locate('Ba_no',_No,[]); end; end;procedure TFrm_DJWH_CHDWH.Get_TempBill; begin //这里控制临时单号的形成,比如取得最小值-1(10000-1) DM.Query_Temp.Close; DM.Query_Temp.SQL.Clear; if KHGL_Caption.Caption='发货单维护' then DM.Query_Temp.SQL.Text:='Select MIN(CONVERT(int,SUBSTRING(Ba_billnum,4,10))) as MinNum from billaffirm where Ba_billnum like ''__F%''' else if KHGL_Caption.Caption='退货单维护' then DM.Query_Temp.SQL.Text:='Select MIN(CONVERT(int,SUBSTRING(Ba_billnum,4,10))) as MinNum from billaffirm where Ba_billnum like ''__X%'''; DM.Query_Temp.Open; //如果取得的单号后5位的最小值≥10000则取9999 if DM.Query_Temp.FieldByName('MinNum').AsInteger>=10000 then _DH:='YYF'+IntToStr(9999) else _DH:='YYF'+IntToStr(DM.Query_Temp.FieldByName('MinNum').AsInteger-1); DM.Query_Temp.Close; end;
怀疑是query没有正常释放,程序在运行几次后就不能再运行了,说内存不足
代码写的很烂:procedure TFrm_DJWH_CHDWH.BTN_AddNoClick(Sender: TObject);
var
_KHBH:string;
_No:integer;
begin
//判断返回结果集不为空时(即存在现有单号),客户编号是否为空
if (not DM.Query_CHDWH.IsEmpty) and ((LKCBB_KHBH.Text=' ') or (LKCBB_KHBH.Text='')) then
begin
MessageDlg('客户编号不能为空,请选择客户编号!',mtInformation,[mbOK],0);
exit;
end;
with DM.Query_CHDWH do
begin
//判断单号是否为空,即判断是否为新增单号
if IsEmpty or (RecordCount<1) then
begin
//Get_TempBill过程生成临时单号
Get_TempBill;
Temp_Bill:=_DH;
DM.Query_Temp.Close;
//得到初始序号
_No:=1;
//客户编号不能为空,所以赋值为空格
_KHBH:=' ';
Close;
SQL.Clear;
SQL.Add('Select * from billaffirm where Ba_billnum='''+_DH+''' order by Ba_no');
RequestLive:=true;
Open;
end
else
begin
//从第一条到最后一条记录进行逐行检查
First;
while not Eof do
begin
if FieldByName('Ba_cmcode').AsString='' then
begin
MessageDlg('客户编号不能为空',mtInformation,[mbOK],0);
LKCBB_KHBH.SetFocus;
Exit;
end;
if FieldByName('Ba_Pdcode1').AsString='' then
begin
MessageDlg('产品编号不能为空',mtInformation,[mbOK],0);
Exit;
end;
if (FieldByName('Ba_PdNum').AsString='') or
(FieldByName('Ba_PdNum').AsInteger=0) then
begin
MessageDlg('产品数量不能为空',mtInformation,[mbOK],0);
Exit;
end;
Next;
end; // end while
_DH:=FieldByName('Ba_billnum').AsString;
//这里得到单号的最大序号
Last;
_No:=FieldByName('Ba_no').AsInteger+1;
_KHBH:=FieldByName('Ba_cmcode').AsString;
end;// end if else
Insert;
Edit;
//以下字段均不允许为空,所以要赋默认值
//单号
FieldByName('Ba_billnum').AsString:=_DH;
//序号
FieldByName('Ba_no').AsInteger:=_No;... ...//客户编号
FieldByName('Ba_cmcode').AsString:=_KHBH;
//制单时间
FieldByName('Ba_maketime').AsDateTime:=now;
Post;
ApplyUpdates;
Close;
RequestLive:=true;
Open;
Locate('Ba_no',_No,[]);
end;
end;procedure TFrm_DJWH_CHDWH.Get_TempBill;
begin
//这里控制临时单号的形成,比如取得最小值-1(10000-1)
DM.Query_Temp.Close;
DM.Query_Temp.SQL.Clear;
if KHGL_Caption.Caption='发货单维护' then
DM.Query_Temp.SQL.Text:='Select MIN(CONVERT(int,SUBSTRING(Ba_billnum,4,10))) as MinNum from billaffirm where Ba_billnum like ''__F%'''
else if KHGL_Caption.Caption='退货单维护' then
DM.Query_Temp.SQL.Text:='Select MIN(CONVERT(int,SUBSTRING(Ba_billnum,4,10))) as MinNum from billaffirm where Ba_billnum like ''__X%''';
DM.Query_Temp.Open;
//如果取得的单号后5位的最小值≥10000则取9999
if DM.Query_Temp.FieldByName('MinNum').AsInteger>=10000 then
_DH:='YYF'+IntToStr(9999)
else
_DH:='YYF'+IntToStr(DM.Query_Temp.FieldByName('MinNum').AsInteger-1);
DM.Query_Temp.Close;
end;