经调试第一次执行到showmessage('4.8'); 第二次在showmessage('4.8');后出错
procedure TForm_main.Button3Click(Sender: TObject);
var once:boolean;
begin
once:=true;
with dm_main.query_select_2 do
begin //A
// dm_main.query_select_2.DisableControls;
first;
while not eof do
begin//B
if once=false then next;
once:=false;
showmessage('1');
with dm_main.query_tmp do
begin //C
close;
sql.clear;
sql.add('select * from t_b_i_movein_detail where cig_code=:cig_code');
parambyname('cig_code').asstring:=dm_main.query_select_2.fieldbyname('cig_code').asstring;
prepare;
open;
end;//C
showmessage(dm_main.query_select_2.fieldbyname('cig_code').asstring);
if dm_main.query_tmp.IsEmpty then
begin//C
showmessage('2.01');
with dm_main.query_insert do
begin //D
showmessage('2.05');
close;
showmessage('2.1');
sql.clear;
showmessage('2.2');
sql.add('insert into t_b_i_movein_detail(cig_code,movein_no,cur_package_amount) values
cig_code,:movein_no,:cur_package_amount)');
params[0].AsString:=dm_main.query_select_2.fieldbyname('cig_code').asstring;
params[1].AsString:=dm_main.query_select_1.fieldbyname('movein_no').asstring;
params[2].AsString:=dm_main.query_select_2.fieldbyname('cur_package_amount').asstring;
showmessage('2.3');
if not (Prepared) then prepare;
showmessage('2.5');
ExecSQL;
showmessage('3');
close;
sql.clear;
sql.add('insert into t_b_i_movein_detail(cig_code,movein_no,cur_package_amount) values
cig_code,:movein_no,:cur_package_amount)');
params[0].AsString:=dm_main.query_select_2.fieldbyname('cig_code').asstring;
params[1].AsString:='0';//dm_main.query_select_1.fieldbyname('movein_no').asstring;
params[2].AsString:=dm_main.query_select_2.fieldbyname('cur_package_amount').asstring;
if not (Prepared) then prepare;
execsql ;
showmessage('4');
end;//D
end//C
else begin //C
showmessage('4.5');
with dm_main.query_insert do
begin //D
close;
showmessage('4.6');
requestlive:=true;
sql.clear;
sql.add('insert into t_b_i_movein_detail(cig_code,movein_no,cur_package_amount) values
cig_code,:movein_no,:cur_package_amount)');
params[0].AsString:=dm_main.query_select_2.fieldbyname('cig_code').asstring;
params[1].AsString:=dm_main.query_select_1.fieldbyname('movein_no').asstring;
params[2].AsString:=dm_main.query_select_2.fieldbyname('cur_package_amount').asstring;
showmessage('4.8');
prepare;
showmessage('5');
ExecSQL;
showmessage('6');
close;
requestlive:=true;
sql.clear;
sql.add('select * from t_b_i_movein_detail where cig_code=:cig_code and movein_no=''0'';');
dm_main.query_insert.parambyname('cig_code').asstring:=dm_main.query_select_2.fieldbyname('cig_code').asstring;
prepare;
open ;
showmessage('6.3');
edit;
showmessage('6.5');
dm_main.query_insert.fieldbyname('cur_package_amount').asfloat:=fieldbyname('cur_package_amount').asfloat+dm_main.query_select_2.fieldbyname('cur_package_amount').asfloat;
post;
showmessage('7');
close;
end; //D
end;//C
end; //B
// dm_main.query_select_2.EnableControls;
end;//A
dm_main.query_select_3.close;
dm_main.query_select_3.Open;
end;