Browse Source

Bug #1317 调差工料,存在未被调用的工料时,右键--价差计算报错

MaiXinRong 10 years ago
parent
commit
7578222601
2 changed files with 16 additions and 10 deletions
  1. 3 0
      DataModules/LeafXmjGlDm.pas
  2. 13 10
      DataModules/ProjectGLDm.pas

+ 3 - 0
DataModules/LeafXmjGlDm.pas

@@ -86,6 +86,7 @@ begin
   idx := sddLeafXmjGL.FindIndex('idxGl');
   iFirst := idx.FindKeyIndex(AGLID);
   iLast := idx.FindKeyLastIndex(AGLID);
+  if iFirst = -1 then Exit;
   for iRec := iFirst to iLast do
   begin
     Rec := idx.Records[iRec];
@@ -102,6 +103,7 @@ begin
   idx := sddLeafXmjGL.FindIndex('idxXmj');
   iFirst := idx.FindKeyIndex(AXmjID);
   iLast := idx.FindKeyLastIndex(AXmjID);
+  if iFirst = -1 then Exit;
   for iRec := iFirst to iLast do
   begin
     Rec := idx.Records[iRec];
@@ -331,6 +333,7 @@ begin
   idx := sddLeafXmjGL.FindIndex('idxGl');
   iFirst := idx.FindKeyIndex(AGLID);
   iLast := idx.FindKeyLastIndex(AGLID);
+  if iFirst = -1 then Exit;
   for iRec := iFirst to iLast do
     vGLs.Add(idx.Records[iRec]);
 end;

+ 13 - 10
DataModules/ProjectGLDm.pas

@@ -668,18 +668,21 @@ begin
     vIdx := LeafXmjGlData.sddLeafXmjGL.FindIndex('idxGL');
     iFirst := vIdx.FindKeyIndex(ARec.ID.AsInteger);
     iLast := vIdx.FindKeyLastIndex(ARec.ID.AsInteger);
-    for i := iFirst to iLast do
+    if (iFirst <> -1) then
     begin
-      XmjGLRec := TLeafXmjGlRecord(vIdx.Records[i]);
-      StageRec := TStageLeafXmjGlRecord(XmjGLRec.StageRec);
-      if Assigned(StageRec) then
+      for i := iFirst to iLast do
       begin
-        fUsedQuantity := fUsedQuantity + StageRec.UsedQuantity.AsFloat;
-        fUsedTotalPrice := fUsedTotalPrice + StageRec.UsedTotalPrice.AsFloat;
-        fPAL_UsedQuantity := fPAL_UsedQuantity + StageRec.PAL_UsedQuantity.AsFloat;
-        fPAL_UsedTotalPrice := fPAL_UsedTotalPrice + StageRec.PAL_UsedTotalPrice.AsFloat;
-        fPAL_DeltaPrice := fPAL_DeltaPrice + StageRec.PAL_DeltaPrice.AsFloat;
-        fPAL_Total := fPAL_Total + StageRec.PAL_Total.AsFloat;
+        XmjGLRec := TLeafXmjGlRecord(vIdx.Records[i]);
+        StageRec := TStageLeafXmjGlRecord(XmjGLRec.StageRec);
+        if Assigned(StageRec) then
+        begin
+          fUsedQuantity := fUsedQuantity + StageRec.UsedQuantity.AsFloat;
+          fUsedTotalPrice := fUsedTotalPrice + StageRec.UsedTotalPrice.AsFloat;
+          fPAL_UsedQuantity := fPAL_UsedQuantity + StageRec.PAL_UsedQuantity.AsFloat;
+          fPAL_UsedTotalPrice := fPAL_UsedTotalPrice + StageRec.PAL_UsedTotalPrice.AsFloat;
+          fPAL_DeltaPrice := fPAL_DeltaPrice + StageRec.PAL_DeltaPrice.AsFloat;
+          fPAL_Total := fPAL_Total + StageRec.PAL_Total.AsFloat;
+        end;
       end;
     end;
   end;