Index: cprs/trunk/CPRS-Chart/Consults/fODProc.pas
===================================================================
--- cprs/trunk/CPRS-Chart/Consults/fODProc.pas	(revision 456)
+++ cprs/trunk/CPRS-Chart/Consults/fODProc.pas	(revision 829)
@@ -6,5 +6,5 @@
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
   fODBase, StdCtrls, ORCtrls, ExtCtrls, ComCtrls, ORfn, uConst, Buttons,
-  Menus;
+  Menus, VA508AccessibilityManager;
 
 type
@@ -59,5 +59,4 @@
     procedure memReasonKeyUp(Sender: TObject; var Key: Word;
       Shift: TShiftState);
-    procedure FormDestroy(Sender: TObject);
     procedure memReasonKeyDown(Sender: TObject; var Key: Word;
       Shift: TShiftState);
@@ -90,5 +89,6 @@
 uses
     rODBase, rConsults, uCore, uConsults, rCore, fConsults, fPCELex, rPCE, ORClasses,
-    clipbrd, fPreReq, uTemplates, uAccessibleRichEdit, fFrame, uODBase;
+    clipbrd, fPreReq, uTemplates, fFrame, uODBase,
+  uVA508CPRSCompatibility;
 
 var
@@ -115,5 +115,4 @@
   inherited;
   DoSetFontSize(MainFontSize);
-  TAccessibleRichEdit.WrapControl(memReason);
   AllowQuickOrder := True;
   FillChar(ProvDx, SizeOf(ProvDx), 0);
@@ -188,5 +187,5 @@
     SetControl(cboProc,       'ORDERABLE', 1);
     if cboProc.ItemIndex < 0 then exit;
-    cboService.Items.Assign(GetProcedureServices(cboProc.ItemIEN));
+    FastAssign(GetProcedureServices(cboProc.ItemIEN), cboService.Items);
     Changing := True;
     tmpResp := TResponse(FindResponseByName('CLASS',1));
@@ -226,6 +225,20 @@
     SetProvDiagPromptingMode;
     GetProvDxandValidateCode(Responses);
+    SetTemplateDialogCanceled(FALSE);
     SetControl(memReason,     'COMMENT',   1);
+    if WasTemplateDialogCanceled then
+    begin
+      AbortOrder := True;
+      Close;
+      Exit;
+    end;
+    SetTemplateDialogCanceled(FALSE);
     SetupReasonForRequest(OrderAction);
+    if WasTemplateDialogCanceled then
+    begin
+      AbortOrder := True;
+      Close;
+      Exit;
+    end;
     Changing := False;
     OrderMessage(ConsultMessage(cboProc.ItemIEN));
@@ -360,5 +373,5 @@
       begin
         Clear;
-        Items.Assign(GetProcedureServices(cboProc.ItemIEN));
+        FastAssign(GetProcedureServices(cboProc.ItemIEN), cboService.Items);
         if Items.Count > 1 then
           ItemIndex := -1
@@ -385,5 +398,5 @@
       with cboService do
         begin
-          Items.Assign(GetProcedureServices(cboProc.ItemIEN));
+          FastAssign(GetProcedureServices(cboProc.ItemIEN), cboService.Items);
           if Items.Count > 1 then
             ItemIndex := -1
@@ -402,7 +415,12 @@
       SetControl(cboPlace,      'PLACE',     1);
       SetControl(txtAttn,       'PROVIDER',  1);
+      SetTemplateDialogCanceled(FALSE);
       SetControl(memReason,     'COMMENT',   1);
-//      if ((cboProc.ItemIEN > 0) and (Length(memReason.Text) = 0)) then
-//        memReason.Lines.Assign(DefaultReasonForRequest(Piece(cboProc.Items[cboProc.ItemIndex], U, 4), True));
+      if WasTemplateDialogCanceled and OrderContainsObjects then
+      begin
+        AbortOrder := TRUE;
+        Close;
+        Exit;
+      end;
       SetupReasonForRequest(ORDER_QUICK);
       GetProvDxandValidateCode(Responses);
@@ -441,5 +459,5 @@
               Exit;
             end;
-          memReason.Lines.Assign(DefaultReasonForRequest(Piece(cboProc.Items[cboProc.ItemIndex], U, 4), True));
+          FastAssign(DefaultReasonForRequest(Piece(cboProc.Items[cboProc.ItemIndex], U, 4), True), memReason.Lines);
           SetupReasonForRequest(ORDER_NEW);
         end;
@@ -457,7 +475,7 @@
   AStringList := TStringList.Create;
   try
-    AStringList.Assign(memReason.Lines);
+    AStringList.Text := memReason.Text;
     LimitStringLength(AStringList, 74);
-    memReason.Lines.Assign(AstringList);
+    memReason.Text := AStringList.Text;
     ControlChange(Self);
   finally
@@ -662,5 +680,5 @@
 begin
   if ((OrderAction = ORDER_QUICK) and (cboProc.ItemID <> '') and (Length(memReason.Text) = 0)) then
-    memReason.Lines.Assign(DefaultReasonForRequest(Piece(cboProc.Items[cboProc.ItemIndex], U, 4), True));
+    FastAssign(DefaultReasonForRequest(Piece(cboProc.Items[cboProc.ItemIndex], U, 4), True), memReason.Lines);
   EditReason := GMRCREAF;
   if EditReason = '' then EditReason := ReasonForRequestEditable(Piece(cboProc.Items[cboProc.ItemIndex], U, 4));
@@ -690,5 +708,5 @@
       if ItemIEN > 0 then
         begin
-          Alist.Assign(GetServicePrerequisites(Piece(Items[ItemIndex], U, 4)));
+          FastAssign(GetServicePrerequisites(Piece(Items[ItemIndex], U, 4)), Alist);
           if AList.Count > 0 then
             begin
@@ -708,5 +726,6 @@
 end;
 
-function TfrmODProc.DefaultReasonForRequest(Service: string; Resolve: Boolean): TStrings;
+function TfrmODProc.DefaultReasonForRequest(Service: string;
+  Resolve: Boolean): TStrings;
 var
   TmpSL: TStringList;
@@ -720,13 +739,21 @@
   try
     Result := GetDefaultReasonForRequest(Piece(cboProc.Items[cboProc.ItemIndex], U, 4), Resolve);
-    TmpSL.Assign(Result);
+    FastAssign(Result, TmpSL);
     x := TmpSL.Text;
     ExpandOrderObjects(x, HasObjects);
     TmpSL.Text := x;
     Responses.OrderContainsObjects := HasObjects;
-    ExecuteTemplateOrBoilerPlate(TmpSL, StrToIntDef(piece(piece(cboProc.Items[cboProc.ItemIndex],U,4),';',1),0),
+    ExecuteTemplateOrBoilerPlate(TmpSL, StrToIntDef(Piece(Piece(cboProc.Items[cboProc.ItemIndex], U, 4), ';', 1), 0),
                    ltProcedure, nil, 'Reason for Request: ' + cboProc.DisplayText[cboProc.ItemIndex], DocInfo);
-    if TmpSL.Text <> x then Responses.OrderContainsObjects := False;
-    Result.Assign(TmpSL);
+    AbortOrder := WasTemplateDialogCanceled;
+    Responses.OrderContainsObjects := HasObjects or TemplateBPHasObjects;
+    if AbortOrder then
+    begin
+      Result.Text := '';
+      Close;
+      Exit;
+    end
+    else
+      FastAssignWith508Msg(TmpSL, Result);
   finally
     TmpSL.Free;
@@ -780,10 +807,4 @@
 end;
 
-procedure TfrmODProc.FormDestroy(Sender: TObject);
-begin
-  inherited;
-  TAccessibleRichEdit.UnwrapControl(memReason);
-end;
-
 procedure TfrmODProc.SetFontSize(FontSize: integer);
 begin
