我写了一段程序,能非常正常运行,然后我在其间加了一个信息提示的Application.MessageBox('xxx','xxx',MB_OK)了之后就报告:project project.exe raised exception class EAccessViolation with message'Access violation at address 0045229b in module 'project.exe'.Read of address 00000208',process stopped.Use Step or Run to continue.我跟踪了一下,发现是在访问一个子对话框中的DBEdit1.Text时,取不到值:
strTemp := form1.DBEdit1.Text;//这里非法访问但是如果把Application.MessageBox('xxx','xxx',MB_OK);注释掉就没有这个问题了,strTemp := form1.DBEdit1.Text就能访问了。好不理解,向各位求教了!~~谢谢~~
strTemp := form1.DBEdit1.Text;//这里非法访问但是如果把Application.MessageBox('xxx','xxx',MB_OK);注释掉就没有这个问题了,strTemp := form1.DBEdit1.Text就能访问了。好不理解,向各位求教了!~~谢谢~~
商榷。
try
if vFrmAddOrderLine.ShowModal() = mrOK then
begin
sItemCode := vFrmAddOrderLine.dblkcbxItemCode.Text;
iQuantity := StrToInt(trim(vFrmAddOrderLine.edtQuantity.Text)); aqItemInv.Close;
aqItemInv.SQL.Clear;
aqItemInv.SQL.Add('select * from T_ITEM_INV where ITEM_CODE=:sItemCode');
aqItemInv.Parameters[0].Value := sItemCode;
aqItemInv.Open; iItemInv :=0;
if not aqItemInv.IsEmpty then
iItemInv :=aqItemInv.FieldByName('QUANTITY').AsInteger; aqItemInv.Close; if iItemInv + iQuantity < 0 then //当iQuantity为负数的时候表示出库
begin
Application.MessageBox('此物料库存不足。','提示',MB_OK);//这里如果注释掉就没有问题
iQuantity := 0 - iItemInv;//调整出库数量为最大库存量
end; with lvOrderLines.Items.Add do
Caption := sItemCode;
SubItems.add(vFrmAddOrderLine.dbedtItemDesc.Text);//如果没有注释messagebox,跟踪到这里出错,注释了之后就没有问题
SubItems.add(vFrmAddOrderLine.dbedtItemUnit.Text);
SubItems.add(IntToStr(iQuantity));
end;
finally
vFrmAddOrderLine.Free;
end;
--------------------------
代码太多了,不好贴,整理了一下,大家看看吧,多谢了
在vFrmAddOrderLine.ShowModal后,vFrmAddOrderLine可能已经从内存释放了(譬如vFrmAddOrderLine的OnClose设置Action := caFree),当然后面所有的引用都可能引起非法访问错误,跟注释或不注释messagebox没有关系,不注释不错只是凑巧而已。
建议你看看TFrm_AddOrderLine单元,或者设置TFrm_AddOrderLine的OnClose中Action := caHide;再重新试试??
正是在vFrmAddOrderLine的OnClose我设置了Action := caFree
:)问题解决了,太感谢你了~~~