begin //按下enter
adoquery1.SQL.clear;
if length(edit1.text)=6 then
adoquery1.SQL.add('select dm,pm,gg,dw,xsjg1,xsjg2,xsjg5,xsjg6 from fw where dm='''+edit1.text+'''')
else
begin
if length(edit1.text) in [4..13] then
adoquery1.SQL.add('select dm,pm,gg,dw,xsjg1,xsjg2,xsjg5,xsjg6 from fw where tm like ''%'+edit1.text+'''')
else
begin
showmessage('请输入商品条形码或代码!');
exit;
end;
end;
adoquery1.open;
if adoquery1.eof then
begin
edit1.Text:='';
showmessage('此商品不存在!请按回车返回重输');
exit;
end
else if adoquery1.recordcount>1 then
begin
application.CreateForm(tdmselectsp,dmselectsp);
dmselectsp.ShowModal;
end; with advstringgrid1 do
begin
if ADOQuery1.FieldbyName('dw').asstring='斤克' then
try
dmszsl.showmodal;
except
application.CreateForm(Tdmszsl,dmszsl);
dmszsl.showmodal;
end
else
begin
Cells[4,i] := inttostr(na);
cells[3,i] :=formatfloat('0.00',ADOQuery1.FieldbyName('xsjg1').asfloat ) ;
end;
cells[1,i] := ADOQuery1.FieldbyName('dm').asstring;
Cells[0,i] := Format('%.3d', [i]);
Cells[2,i] := ADOQuery1.FieldbyName('pm').asstring;
cells[5,i] :=formatfloat('0.00',strtofloat(cells[3,i])*strtofloat(cells[4,i]));
row:=i;
na:=1;
jehj:=0;
for j:=1 to i do
begin
jehj:=jehj+strtofloat(dmctxs.advstringgrid1.cells[5,j]);
end;
I:=I+1;
RowCount :=rowcount+1;
dmctxs.edit1.text:='';
end;
end;
adoquery1.SQL.clear;
if length(edit1.text)=6 then
adoquery1.SQL.add('select dm,pm,gg,dw,xsjg1,xsjg2,xsjg5,xsjg6 from fw where dm='''+edit1.text+'''')
else
begin
if length(edit1.text) in [4..13] then
adoquery1.SQL.add('select dm,pm,gg,dw,xsjg1,xsjg2,xsjg5,xsjg6 from fw where tm like ''%'+edit1.text+'''')
else
begin
showmessage('请输入商品条形码或代码!');
exit;
end;
end;
adoquery1.open;
if adoquery1.eof then
begin
edit1.Text:='';
showmessage('此商品不存在!请按回车返回重输');
exit;
end
else if adoquery1.recordcount>1 then
begin
application.CreateForm(tdmselectsp,dmselectsp);
dmselectsp.ShowModal;
end; with advstringgrid1 do
begin
if ADOQuery1.FieldbyName('dw').asstring='斤克' then
try
dmszsl.showmodal;
except
application.CreateForm(Tdmszsl,dmszsl);
dmszsl.showmodal;
end
else
begin
Cells[4,i] := inttostr(na);
cells[3,i] :=formatfloat('0.00',ADOQuery1.FieldbyName('xsjg1').asfloat ) ;
end;
cells[1,i] := ADOQuery1.FieldbyName('dm').asstring;
Cells[0,i] := Format('%.3d', [i]);
Cells[2,i] := ADOQuery1.FieldbyName('pm').asstring;
cells[5,i] :=formatfloat('0.00',strtofloat(cells[3,i])*strtofloat(cells[4,i]));
row:=i;
na:=1;
jehj:=0;
for j:=1 to i do
begin
jehj:=jehj+strtofloat(dmctxs.advstringgrid1.cells[5,j]);
end;
I:=I+1;
RowCount :=rowcount+1;
dmctxs.edit1.text:='';
end;
end;
把交互代码同实现代码分开到不同函数吧。
下面是一个完整的过程
你的程序begin end没有修改
你再看看整个过程的begin end;有没有问题
再检查其他过程
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
j:integer;
begin //此处?
j:=0;
adoquery1.SQL.clear;
if length(edit1.text)=6 then
adoquery1.SQL.add('select dm,pm,gg,dw,xsjg1,xsjg2,xsjg5,xsjg6 from fw where dm='''+edit1.text+'''')
else
begin
if length(edit1.text) in [4..13] then
adoquery1.SQL.add('select dm,pm,gg,dw,xsjg1,xsjg2,xsjg5,xsjg6 from fw where tm like ''%'+edit1.text+'''')
else
begin
showmessage('请输入商品条形码或代码!');
exit;
end;
end;
adoquery1.open;
if adoquery1.eof then
begin
edit1.Text:='';
showmessage('此商品不存在!请按回车返回重输');
exit;
end
else if adoquery1.recordcount>1 then
begin
showmessage(inttostr(j));//application.CreateForm(tdmselectsp,dmselectsp);
showmessage(inttostr(j));// dmselectsp.ShowModal;
end; with advstringgrid1 do
begin
if ADOQuery1.FieldbyName('dw').asstring='斤克' then
try
showmessage(inttostr(j));//dmszsl.showmodal;
except
showmessage(inttostr(j));// application.CreateForm(Tdmszsl,dmszsl);
showmessage(inttostr(j)); // dmszsl.showmodal;
end
else
begin
showmessage(inttostr(j));//Cells[4,i] := inttostr(na);
showmessage(inttostr(j));//cells[3,i] :=formatfloat('0.00',ADOQuery1.FieldbyName('xsjg1').asfloat ) ;
end;
showmessage(inttostr(j));//cells[1,i] := ADOQuery1.FieldbyName('dm').asstring;
showmessage(inttostr(j)); //Cells[0,i] := Format('%.3d', [i]);
showmessage(inttostr(j));// Cells[2,i] := ADOQuery1.FieldbyName('pm').asstring;
showmessage(inttostr(j)); // cells[5,i] :=formatfloat('0.00',strtofloat(cells[3,i])*strtofloat(cells[4,i]));
showmessage(inttostr(j));// row:=i;
showmessage(inttostr(j));// na:=1;
showmessage(inttostr(j));// jehj:=0;
for j:=1 to 10 do
begin
showmessage(inttostr(j));// jehj:=jehj+strtofloat(dmctxs.advstringgrid1.cells[5,j]);
end;
showmessage(inttostr(j));//I:=I+1;
showmessage(inttostr(j));//RowCount :=rowcount+1;
showmessage(inttostr(j));//dmctxs.edit1.text:='';
end;
end; //此处?
end.//窗体结尾是否有问题
后来弄了半天才发现,那位老兄用Exit给一个Button命名,真是吐血呀~~
检查是不是有我类似的情况~~
Exit 替换成 System.Exit; 看看~~另外说一句,你的代码风格真的很差,参考Delphi Source吧~~