Index: cprs/trunk/CPRS-Chart/Orders/fOMSet.pas
===================================================================
--- cprs/trunk/CPRS-Chart/Orders/fOMSet.pas	(revision 829)
+++ cprs/trunk/CPRS-Chart/Orders/fOMSet.pas	(revision 1679)
@@ -109,7 +109,9 @@
   SetItem: TSetItem;
   theOwner: TComponent;
+  ok: boolean;
 
   procedure SkipToNext;
   begin
+    if FClosing then Exit;
     lstSet.Checked[lstSet.ItemIndex] := True;
     DoNextItem;
@@ -117,5 +119,5 @@
 
 begin
-  DoingNextItem := true;
+   DoingNextItem := true;
   //frmFrame.UpdatePtInfoOnRefresh;
   if FClosing then Exit;
@@ -144,9 +146,38 @@
     'A':      if not ActivateAction(IntToStr(SetItem.DialogIEN), Self, ItemIndex) then
               begin
-                if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
-                  lstSet.Checked[lstSet.ItemIndex] := True
-                else SkipToNext;
+                if Not FClosing then
+                begin
+                  if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
+                    lstSet.Checked[lstSet.ItemIndex] := True
+                  else SkipToNext;
+                end;
               end;
     'D', 'Q': if not ActivateOrderDialog(IntToStr(SetItem.DialogIEN), FDelayEvent, Self, ItemIndex) then
+              begin
+                if Not FClosing then
+                begin
+                  if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
+                    lstSet.Checked[lstSet.ItemIndex] := True
+                  else SkipToNext;
+                end;
+              end;
+    'M':      begin
+                ok := ActivateOrderMenu(IntToStr(SetItem.DialogIEN), FDelayEvent, Self, ItemIndex);
+                if not FClosing then
+                begin
+                  if ok then
+                    Inc(FActiveMenus)
+                  else
+                  begin
+                    if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
+                      lstSet.Checked[lstSet.ItemIndex] := True
+                    else
+                      SkipToNext;
+                  end;
+                end;
+              end;
+    'O':      begin
+                if (Self.Owner.Name = 'frmOMNavA') then theOwner := Self.Owner else theOwner := self;
+                if not ActivateOrderSet( IntToStr(SetItem.DialogIEN), FDelayEvent, theOwner, ItemIndex) then
                 begin
                   if Not FClosing then
@@ -157,21 +188,4 @@
                   end;
                 end;
-    'M':      if ActivateOrderMenu(  IntToStr(SetItem.DialogIEN), FDelayEvent, Self, ItemIndex)
-                then Inc(FActiveMenus)
-                else
-                begin
-                  if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
-                    lstSet.Checked[lstSet.ItemIndex] := True
-                  else
-                    SkipToNext;
-                end;
-    'O':      begin
-                if (Self.Owner.Name = 'frmOMNavA') then theOwner := Self.Owner else theOwner := self;
-                if not ActivateOrderSet( IntToStr(SetItem.DialogIEN), FDelayEvent, theOwner, ItemIndex) then
-                begin
-                  if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
-                    lstSet.Checked[lstSet.ItemIndex] := True
-                  else SkipToNext;
-                end;
               end;
     else      begin
@@ -186,10 +200,19 @@
 procedure TfrmOMSet.UMDelayEvent(var Message: TMessage);
 begin
+  if CloseRequested then
+  begin
+    Close;
+    if Not FClosing then
+      begin
+        CloseRequested := False;
+        FClosing := False;
+        DoNextItem;
+      end
+      else Exit;
+  end;
   // ignore if delay from other than current itemindex
   // (prevents completion of an order set from calling DoNextItem)
   if Message.WParam = lstSet.ItemIndex then
     if lstSet.ItemIndex < lstSet.Items.Count - 1 then DoNextItem else Close;
-  if CloseRequested then
-    Close;
 end;
 
@@ -252,4 +275,5 @@
  else if lstSet.ItemIndex < (lstSet.Items.Count - 1)
    then CanClose := InfoBox(TX_STOP, TC_STOP, MB_YESNO) = IDYES;
+   FClosing := CanClose;
 end;
 
@@ -281,5 +305,8 @@
 begin
   if DoingNextItem then
-    CloseRequested := true              //Fix for CQ: 8297
+  begin
+    CloseRequested := true;             //Fix for CQ: 8297
+    FClosing := true;
+  end
   else
     Close;
