我有一个用delphi xe2编写的3层应用程序。在组合编辑中输入数据并按Tab键时,应用程序将自动退出,并显示错误消息stack overflow
。我在combo编辑退出事件中附加了代码:
Procedure TFormSalesReturn.ComboEditBillNumberExit(Sender: TObject);
Begin
Try
LabelBillNumber.Font.Style := LabelBillNumber.Font.Style - [fsBold];
dBillDiscountPercentage := 0;
If (ComboEditBillNumber.Text <> '') Then
Begin
If (ComboEditBillNumber.Modified) Then
Begin
Try
If Pos('/', Trim(ComboEditBillNumber.Text)) = 0 Then
ComboEditBillNumber.Text := FormMDIMain.sBranchcode +
FormMDIMain.sCurrentFinancialYear + '/' +
FormMDIMain.FuncStrZero(Trim(ComboEditBillNumber.Text), 6);
Except
on E: Exception Do
begin
MessageDlg('Cannot Load Bill' + E.Message, mtError,
[MbOk], 0);
end
End;
End;
with DataModuleClient.ClntDSetGeneral do
Begin
Close;
SQL.clear;
SQL.Add('SELECT BILLNUMBER,BILLTYPE FROM BILLCANCELREQUEST WHERE BILLNUMBER = :BILLNUMBER AND BILLTYPE = :BILLTYPE');
Params.ParamByName('BILLNUMBER').AsString :=
Trim(ComboEditBillNumber.Text);
Params.ParamByName('BILLTYPE').AsString :=
QueryLookupBillType.FieldByname('BILLTYPE').AsString;
Open;
if Not IsEmpty then
begin
MessageDlg('Cannot return cancel requested bills !', mtWarning,
[MbOk], 0);
Abort;
end;
End;
With QueryGeneral Do
Begin
Close;
SQL.clear;
SQL.Add('SELECT CASHBILL, CREDITBILLTYPE, BILLNUMBER, BILLAMOUNT,BILLDISCOUNT,BILLDATE,PATIENTNAME FROM BILLMASTER WHERE BILLTYPE = '
+ '''' + QueryLookupBillType.FieldByname('BILLTYPE').AsString +
'''' + ' AND BILLNUMBER = ' + '''' + ComboEditBillNumber.Text +
'''' + ' AND BILLCANCELLED<>''' + 'Y' + '''');
If FormSalesReturn.ComboEditOpNumber.Text <> '' Then
SQL.Add(' AND OPNUMBER = ' + '''' +
FormSalesReturn.ComboEditOpNumber.Text + '''');
Open;
CurrencyBillAmount.Value := FieldByname('BILLAMOUNT').AsCurrency;
if ((QueryGeneral.FieldByname('BILLDISCOUNT').AsCurrency <> 0.00) Or
(QueryGeneral.FieldByname('BILLAMOUNT').AsCurrency <> 0.00)) then
dBillDiscountPercentage :=
(FieldByname('BILLDISCOUNT').AsCurrency * 100) /
(FieldByname('BILLAMOUNT').AsCurrency +
FieldByname('BILLDISCOUNT').AsCurrency);
If (FormMDIMain.sReturnPeriod > 0) And Not(IsEmpty) Then
Begin
With DataMain.QuerySysDate Do
Begin
Close;
Params.ParamByName('BRANCHCODE').AsString :=
FormMDIMain.sBranchcode;
Open;
If ((StrToDate(FormatDateTime('dd/mm/yyyy',
FieldByname('SYSDATE').AsDateTime)) -
StrToDate(FormatDateTime('dd/mm/yyyy',
QueryGeneral.FieldByname('BILLDATE').AsDateTime))) >
FormMDIMain.sReturnPeriod) Then
Begin
MessageDlg
('Item sold before the allowed time, cannot enter returns!',
mtInformation, [MbOk], 0);
ComboEditBillNumber.SetFocus;
End;
End;
End;
If FieldByname('CASHBILL').AsString = IBRdGrpPaymentMode.Value Then
Begin
If FieldByname('CASHBILL').AsString = 'N' Then
Begin
If Trim(IBComboGroupType.Text) = 'IPCREDIT' Then
Begin
If (Trim(FieldByname('CREDITBILLTYPE').AsString) <>
'IP CREDITS') Then
Begin
MessageDlg('payment mode variations found !',
mtInformation, [MbOk], 0);
ComboEditBillNumber.SetFocus;
End // Added on 26/05/2014
Else If (Trim(FieldByname('CREDITBILLTYPE').AsString)
= 'IP CREDITS') Then
Begin
with DataModuleClient.ClntDSetGeneral do
Begin
Close;
SQL.clear;
SQL.Add('SELECT DISCHARGED FROM IPMASTER WHERE IPNUMBER = :IPNUMBER AND IPSERIALNUMBER = :IPSERIALNUMBER');
Params.ParamByName('IPNUMBER').AsString :=
sOriginalIpNumber;
Params.ParamByName('IPSERIALNUMBER').AsString :=
IBEditSlNo.Text;
Open;
If (DataModuleClient.ClntDSetGeneral.FieldByname
('DISCHARGED').AsString = 'Y') Then
Begin
If (lFlag = False) Then
MessageDlg
('Since patient is discharged this bill should be saved as cash bill',
mtWarning, [MbOk], 0);
lFlag := True;
End;
End;
End;
End
Else If IBComboGroupType.Text = 'OTHERS' Then
Begin
If ((Trim(FieldByname('CREDITBILLTYPE').AsString)
= 'CREDIT CARD') Or
(Trim(FieldByname('CREDITBILLTYPE').AsString)
= 'IP CREDITS')) Then
Begin
MessageDlg('payment mode variations found !',
mtInformation, [MbOk], 0);
ComboEditBillNumber.SetFocus;
End;
End;
End;
End;
If FieldByname('CASHBILL').AsString <> IBRdGrpPaymentMode.Value Then
Begin
If (Trim(FieldByname('CREDITBILLTYPE').AsString)
= 'IP CREDITS') Then
Begin
with DataModuleClient.ClntDSetGeneral do
Begin
Close;
SQL.clear;
SQL.Add('SELECT DISCHARGED FROM IPMASTER WHERE IPNUMBER = :IPNUMBER AND IPSERIALNUMBER = :IPSERIALNUMBER');
Params.ParamByName('IPNUMBER').AsString :=
sOriginalIpNumber;
Params.ParamByName('IPSERIALNUMBER').AsString :=
IBEditSlNo.Text;
Open;
If (DataModuleClient.ClntDSetGeneral.FieldByname
('DISCHARGED').AsString <> 'Y') Then
Begin
MessageDlg('payment mode variations found !',
mtInformation, [MbOk], 0);
ComboEditBillNumber.SetFocus;
End;
End;
End
Else
Begin
If (Trim(FieldByname('CREDITBILLTYPE').AsString) <>
'CREDIT CARD') Then
Begin
MessageDlg('payment mode variations found !',
mtInformation, [MbOk], 0);
ComboEditBillNumber.SetFocus;
End;
End;
End;
If (IsEmpty) Then
Begin
ShowMessage('Bill Not Found!');
ComboEditBillNumber.Text := '';
ComboEditBillNumber.SetFocus;
End
End;
End;
QueryMaterials.Close;
QueryMaterials.Open;
If (QueryMaterials.FieldByname('BILLWISERETURN').AsString = 'Y') Then
Begin
If (Trim(IBLookupComboBillType.Text) <> '') And
(Trim(ComboEditBillNumber.Text) <> '') Then
Begin
IBLookupComboBillItems.Enabled := True;
CurrencyBillAmount.Enabled := True;
EditFilter.Enabled := True;
End
Else
Begin
IBLookupComboBillItems.Enabled := False;
CurrencyBillAmount.Enabled := False;
EditFilter.Enabled := False;
End;
End
Else
Begin
IBLookupComboBillItems.Enabled := True;
CurrencyBillAmount.Enabled := True;
EditFilter.Enabled := True;
End;
If EditFilter.Enabled Then
EditFilter.SetFocus;
QueryLookupItemName.Close;
Except
on E: Exception Do
begin
MessageDlg(E.Message, mtError, [MbOk], 0);
end;
End;
End;