Record have been changed by another user

I use Delphi Version 5 , Use MIDAS for 3-Tier Application pass the Oracle8 Enterprise Edition Release 8.0.5.1.0 .
I have header / detail table of Invoice.
Process I : Insert Header / Details of Invoice
Process II: Post Header / Apply Update Header
Process III: Post Details / Apply Update Details
Process IV: Calculate Vat from Invoice Header
Process V : Edit , Post , ApplyUpdate Invoice
Header
Process VI : ApplyUpdate Invoice Header

I face the error "Record have been changed by another user on Process VI

***Coding Process II - V as below***
try
with dmdInvoice do
begin
strInvoiceNo := edtInvNo.Text;
strVendorCode := dblcdVendorCode.LookupValue;
strPONO := DBEdit3.Text;
dtInvoiceDate := StrToDate(FormatDateTime('mm/dd/yyyy',wwDBDateTimePicker1.Date));

if dsrInvoiceHeader.State in [dsEdit, dsInsert] then
begin
cdsInvoiceHeader.Post;
if cdsInvoiceHeader.ApplyUpdates(0) > 0 then

cdsInvoiceLinesItem.Post;
if cdsInvoiceLinesItem.ApplyUpdates(0) >0 then

cdsInvoiceHeader.Close;
cdsInvoiceHeader.Open;

cdsInvoiceHeader.Locate('INVOICE_NO;INVOICE_DATE;PO_NO;VENDOR_CODE',VarArrayOf([strInvoiceNo,dtInvoiceDate,strPONO,strVendorCode]),[]);
end
else
begin
cdsInvoiceHeader.Edit;
cdsInvoiceHeader.Post;
if cdsInvoiceHeader.ApplyUpdates(0) > 0 then

cdsInvoiceLinesItem.Post;
if cdsInvoiceLinesItem.ApplyUpdates(0)>0 then

cdsInvoiceHeader.Close;
cdsInvoiceHeader.Open;

cdsInvoiceHeader.Locate('INVOICE_NO;INVOICE_DATE;PO_NO;VENDOR_CODE',VarArrayOf([strInvoiceNo,dtInvoiceDate,strPONO,strVendorCode]),[]);

end;

if cdsInvoiceHeader.Locate('INVOICE_NO;INVOICE_DATE;PO_NO;VENDOR_CODE',VarArrayOf([strInvoiceNo,dtInvoiceDate,strPONO,strVendorCode]),[]) then
begin

strCommand := 'select t.* from ssi_gp_cal_vat_invoice_v t where t.invoice_no='+#39+edtInvNo.Text+#39+' and t.invoice_date=TO_DATE('+#39+FormatDateTime('mm/dd/yyyy',wwDBDateTimePicker1.Date)+#39+','+#39+'MM/DD/YYYY'+#39+') and t.po_no='+#39+DBEdit3.Text+#39+' and t.vendor_code='+#39+dblcdVendorCode.LookupValue+#39;

cdsCalVATInvoice.Close;
cdsCalVATInvoice.CommandText :=strCommand;
cdsCalVATInvoice.Open;

if cdsCalVATInvoice.RecordCount > 0 then
begin
//Calculate VAT
cdsInvoiceHeader.Edit;
cdsInvoiceHeader.FieldByName('AMOUNT_BEFORE_VAT').AsFloat := cdsCalVATInvoice.FieldByName('SUM_AMOUNT_BEFORE_VAT').Value;
cdsInvoiceHeader.FieldByName('VAT').AsFloat := cdsCalVATInvoice.FieldByName('VAT_OF_SUM_AMOUNT').Value;
cdsInvoiceHeader.FieldByName('AMOUNT_AFTER_VAT').AsFloat := (cdsCalVATInvoice.FieldByName('SUM_AMOUNT_BEFORE_VAT').Value + cdsCalVATInvoice.FieldByName('VAT_OF_SUM_AMOUNT').Value);

cdsInvoiceHeader.Post;

FrmSplash.Free;
Screen.Cursor := crArrow;
ShowMessage('Complete Cal. VAT');

end;
end
else
begin
frmSplash.Free;
Screen.Cursor := crArrow;
ShowMessage('You will be Cal. VAT again.');
end;
end;//with
except
frmSplash.Free;
Screen.Cursor := crArrow;
raise;

end;//try

***Coding Process VI as below***
with dmdInvoice do
begin
strInvoiceNo := edtInvNo.Text;
strVendorCode := dblcdVendorCode.LookupValue;
strPONO := DBEdit3.Text;
dtInvoiceDate := StrToDate(FormatDateTime('mm/dd/yyyy',wwDBDateTimePicker1.Date));
end;//with
try
with dmdInvoice do
begin

cdsInvoiceHeader.ApplyUpdates(0);
cdsInvoiceLinesItem.ApplyUpdates(0);

cdsInvoiceHeader.Close;
cdsInvoiceHeader.Open;
cdsInvoiceHeader.Locate('INVOICE_NO;INVOICE_DATE;PO_NO;VENDOR_CODE',VarArrayOf([strInvoiceNo,dtInvoiceDate,strPONO,strVendorCode]),[]);

edtCalCheckAmountChange(edtCalCheckAmount);

frmSplash.Free;
Screen.Cursor := crArrow;
ShowMessage('Complete Apply Invoice');

end;//with

except
raise;
end;//try

Please help me , Thanks you for you kindly to help me.

P.Suchada
 
The "Record is changed by another user" error message can indicate 2 things:

1. The record is changed in the database since the dataset was opened. This doesn't necessarily have to be another user, it could even be the same application.

2. The field list of the query includes an expression with an alias that is the same as a column name. For example:

select upper(ename) as ename, rowid from emp

The ename in the result set of the dataset is not the same as in the database, and therefore the dataset concludes that the record is changed.

------------------
Marco Kalter
Allround Automations
 
Back
Top