46. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 3/22/2018 8:26:01 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

46.1 Files compared

# Location File Last Modified
1 OR_30_405V42.zip\OR_30_405V42_SRC\Templates uTemplateFields.pas Wed Jan 17 18:08:08 2018 UTC
2 OR_30_405V42.zip\OR_30_405V42_SRC\Templates uTemplateFields.pas Wed Mar 21 14:43:44 2018 UTC

46.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 6 5386
Changed 5 10
Inserted 0 0
Removed 0 0

46.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

46.4 Active regular expressions

No regular expressions were active.

46.5 Comparison detail

  1   unit uTemp lateFields ;
  2  
  3   interface
  4  
  5   uses
  6     Forms, S ysUtils, C lasses, Di alogs, Std Ctrls, Ext Ctrls, Con trols, Con tnrs,
  7     Graphics , ORClasse s, ComCtrl s, ORDtTm,  uDlgCompo nents, Typ Info, ORFn , StrUtils , uConst,  ORNet;
  8  
  9   type
  10     TTemplat eFieldType  = (dftUnk nown, dftE ditBox, df tComboBox,  dftButton , dftCheck Boxes,
  11       dftRad ioButtons,  dftDate,  dftNumber,  dftHyperl ink, dftWP , dftText,
  12   // keep df tScreenRea der as las t entry -  users can  not create  this type  of field
  13       dftScr eenReader) ;
  14  
  15     TTmplFld DateType =  (dtUnknow n, dtDate,  dtDateTim e, dtDateR eqTime,
  16                                       dtCombo , dtYear,  dtYearMont h);
  17  
  18   const
  19     FldItemT ypes  = [d ftComboBox , dftButto n, dftChec kBoxes, df tRadioButt ons, dftWP , dftText] ;
  20     SepLines Types = [d ftCheckBox es, dftRad ioButtons] ;
  21     EditLenT ypes  = [d ftEditBox,  dftComboB ox, dftWP] ;
  22     EditDflt Types = [d ftEditBox,  dftHyperl ink];
  23     EditDflt Type2 = [d ftEditBox,  dftHyperl ink, dftDa te];
  24     ItemDflt Types = [d ftComboBox , dftButto n, dftChec kBoxes, df tRadioButt ons];
  25     NoRequir ed    = [d ftHyperlin k, dftText ];
  26     ExcludeT ext   = [d ftHyperlin k, dftText ];
  27     DateComb oTypes = [ dtCombo, d tYear, dtY earMonth];
  28  
  29   type
  30     TTemplat eDialogEnt ry = class (TObject)
  31     private
  32       FID: s tring;
  33       FFont:  TFont;
  34       FPanel : TDlgFiel dPanel;
  35       FContr ols: TStri ngList;
  36       FInden ts: TStrin gList;
  37       FFirst Build: boo lean;
  38       FOnCha nge: TNoti fyEvent;
  39       FText:  string;
  40       FInter nalID: str ing;
  41       FObj:  TObject;
  42       FField Values: st ring;
  43       FUpdat ing: boole an;
  44       FAutoD estroyOnPa nelFree: b oolean;
  45       FPanel Dying: boo lean;
  46       FOnDes troy: TNot ifyEvent;
  47       proced ure KillLa bels;
  48       functi on GetFiel dValues: s tring;
  49       proced ure SetFie ldValues(c onst Value : string);
  50       proced ure SetAut oDestroyOn PanelFree( const Valu e: boolean );
  51       functi on StripCo de(var txt : string;  code: char ): boolean ;
  52     protecte d
  53       proced ure UpDown Change(Sen der: TObje ct);
  54       proced ure DoChan ge(Sender:  TObject);
  55       functi on GetCont rolText(Ct rlID: inte ger; NoCom mas: boole an;
  56                                 va r FoundEnt ry: boolea n; AutoWra p: boolean ;
  57                                 em Field: str ing = '';  CrntLnTxt:  String =  '';  AutoW rapIndent: Integer =  0;
  58                                 No Format: Bo olean = fa lse): stri ng;
  59       functi on GetCont rol(CtrlID : integer) : TControl ; // NSR20 100706 AA  2015/10/09
  60       proced ure SetCon trolText(C trlID: int eger; ATex t: string) ;
  61     public
  62       constr uctor Crea te(AParent : TWinCont rol; AID,  Text: stri ng);
  63       destru ctor Destr oy; overri de;
  64       functi on GetPane l(MaxLen:  integer; A Parent: TW inControl;
  65                           OwningCh eckBox: TC PRSDialogP arentCheck Box): TDlg FieldPanel ;
  66       functi on GetText : string;
  67       proper ty Text: s tring read  FText wri te FText;
  68       proper ty Interna lID: strin g read FIn ternalID w rite FInte rnalID;
  69       proper ty ID: str ing read F ID;
  70       proper ty Obj: TO bject read  FObj writ e FObj;
  71       proper ty OnChang e: TNotify Event read  FOnChange  write FOn Change;
  72       proper ty OnDestr oy: TNotif yEvent rea d FOnDestr oy write F OnDestroy;
  73       proper ty FieldVa lues: stri ng read Ge tFieldValu es write S etFieldVal ues;
  74       proper ty AutoDes troyOnPane lFree: boo lean read  FAutoDestr oyOnPanelF ree
  75                                                    write  SetAutoDe stroyOnPan elFree;
  76     end;
  77  
  78     TTemplat eField = c lass(TObje ct)
  79     private
  80       FMaxLe n: integer ;
  81       FFldNa me: string ;
  82       FNameC hanged: bo olean;
  83       FLMTex t: string;
  84       FEditD efault: st ring;
  85       FNotes : string;
  86       FItems : string;
  87       FInact ive: boole an;
  88       FItemD efault: st ring;
  89       FFldTy pe: TTempl ateFieldTy pe;
  90       FRequi red: boole an;
  91       FSepLi nes: boole an;
  92       FTextL en: intege r;
  93       FInden t: integer ;
  94       FPad:  integer;
  95       FMinVa l: integer ;
  96       FMaxVa l: integer ;
  97       FIncre ment: inte ger;
  98       FURL:  string;
  99       FDateT ype: TTmpl FldDateTyp e;
  100       FModif ied: boole an;
  101       FID: s tring;
  102       FLocke d: boolean ;
  103       FCommu nityCare:  boolean;
  104       proced ure SetEdi tDefault(c onst Value : string);
  105       proced ure SetFld Name(const  Value: st ring);
  106       proced ure SetFld Type(const  Value: TT emplateFie ldType);
  107       proced ure SetIna ctive(cons t Value: b oolean);
  108       proced ure SetReq uired(cons t Value: b oolean);
  109       proced ure SetSep Lines(cons t Value: b oolean);
  110       proced ure SetIte mDefault(c onst Value : string);
  111       proced ure SetIte ms(const V alue: stri ng);
  112       proced ure SetLMT ext(const  Value: str ing);
  113       proced ure SetMax Len(const  Value: int eger);
  114       proced ure SetNot es(const V alue: stri ng);
  115       proced ure SetID( const Valu e: string) ;
  116       proced ure SetInc rement(con st Value:  integer);
  117       proced ure SetInd ent(const  Value: int eger);
  118       proced ure SetMax Val(const  Value: int eger);
  119       proced ure SetMin Val(const  Value: int eger);
  120       proced ure SetPad (const Val ue: intege r);
  121       proced ure SetTex tLen(const  Value: in teger);
  122       proced ure SetURL (const Val ue: string );
  123       functi on GetTemp lateFieldD efault: st ring;
  124       proced ure Create DialogCont rols(Entry : TTemplat eDialogEnt ry;
  125                                         var I ndex: Inte ger; CtrlI D: integer );
  126       functi on SaveErr or: string ;
  127       functi on Width:  integer;
  128       functi on GetRequ ired: bool ean;
  129       proced ure SetDat eType(cons t Value: T TmplFldDat eType);
  130     public
  131       constr uctor Crea te(AData:  TStrings);
  132       destru ctor Destr oy; overri de;
  133       proced ure Assign (AFld: TTe mplateFiel d);
  134       functi on NewFiel d: boolean ;
  135       functi on CanModi fy: boolea n;
  136       proper ty ID: str ing read F ID write S etID;
  137       proper ty FldName : string r ead FFldNa me write S etFldName;
  138       proper ty NameCha nged: bool ean read F NameChange d;
  139       proper ty FldType : TTemplat eFieldType  read FFld Type write  SetFldTyp e;
  140       proper ty MaxLen:  integer r ead FMaxLe n write Se tMaxLen;
  141       proper ty EditDef ault: stri ng read FE ditDefault  write Set EditDefaul t;
  142       proper ty Items:  string rea d FItems w rite SetIt ems;
  143       proper ty ItemDef ault: stri ng read FI temDefault  write Set ItemDefaul t;
  144       proper ty LMText:  string re ad FLMText  write Set LMText;
  145       proper ty Inactiv e: boolean  read FIna ctive writ e SetInact ive;
  146       proper ty Require d: boolean  read GetR equired wr ite SetReq uired;
  147       proper ty SepLine s: boolean  read FSep Lines writ e SetSepLi nes;
  148       proper ty TextLen : integer  read FText Len write  SetTextLen ;
  149       proper ty Indent:  integer r ead FInden t write Se tIndent;
  150       proper ty Pad: in teger read  FPad writ e SetPad;
  151       proper ty MinVal:  integer r ead FMinVa l write Se tMinVal;
  152       proper ty MaxVal:  integer r ead FMaxVa l write Se tMaxVal;
  153       proper ty Increme nt: intege r read FIn crement wr ite SetInc rement;
  154       proper ty URL: st ring read  FURL write  SetURL;
  155       proper ty DateTyp e: TTmplFl dDateType  read FDate Type write  SetDateTy pe;
  156       proper ty Notes:  string rea d FNotes w rite SetNo tes;
  157       proper ty Templat eFieldDefa ult: strin g read Get TemplateFi eldDefault ;
  158       proper ty Communi tyCare: bo olean read  FCommunit yCare;
  159     end;
  160  
  161     TIntStru c = class( TObject)
  162     public
  163       x: int eger;
  164     end;
  165  
  166   function G etDialogEn try(AParen t: TWinCon trol; AID,  AText: st ring): TTe mplateDial ogEntry;
  167   procedure  FreeEntrie s(SL: TStr ings);
  168   procedure  AssignFiel dIDs(var T xt: string ); overloa d;
  169   procedure  AssignFiel dIDs(SL: T Strings);  overload;
  170   function R esolveTemp lateFields (Text: str ing; AutoW rap: boole an; Hidden : boolean  = FALSE; I ncludeEmbe dded: bool ean = FALS E; AutoWra pIndent: I nteger = 0 ): string;
  171   function A reTemplate FieldsRequ ired(const  Text: str ing; FldVa lues: TORS tringList  =  nil): b oolean;
  172   function H asTemplate Field(txt:  string):  boolean;
  173  
  174   function G etTemplate Field(ATem plateField : string;  ByIEN: boo lean): TTe mplateFiel d;
  175   function T emplateFie ldNameProb lem(Fld: T TemplateFi eld): bool ean;
  176   function S aveTemplat eFieldErro rs: string ;
  177   procedure  ClearModif iedTemplat eFields;
  178   function A nyTemplate FieldsModi fied: bool ean;
  179   procedure  ListTempla teFields(c onst AText : string;  AList: TSt rings; Lis tErrors: b oolean = F ALSE);
  180   function B oilerplate TemplateFi eldsOK(con st AText:  string; Ms g: string  = ''): boo lean;
  181   procedure  EnsureText (edt: TEdi t; ud: TUp Down);
  182   procedure  ConvertCod es2Text(sl : TStrings ; Short: b oolean);
  183   function S tripEmbedd ed(iItems:  string):  string;
  184   procedure  StripScree nReaderCod es(var Tex t: string) ; overload ;
  185   procedure  StripScree nReaderCod es(SL: TSt rings); ov erload;
  186   function H asScreenRe aderBreakC odes(SL: T Strings):  boolean;
  187   function g etUTmplFld s: TList;/ / NSR20100 706 AA 201 0/10/09
  188  
  189   const
  190     Template FieldSigna ture = '{F LD';
  191     Template FieldBegin Signature  = Template FieldSigna ture + ':' ;
  192     Template FieldEndSi gnature =  '}';
  193     ScreenRe aderCodeSi gnature =  '{SR-';
  194     ScreenRe aderCodeTy pe = '  Sc reen Reade r Code';
  195     ScreenRe aderCodeCo unt = 2;
  196     ScreenRe aderShownC ount = 1;
  197     ScreenRe aderStopCo de = Scree nReaderCod eSignature  + 'STOP'  + Template FieldEndSi gnature;
  198     ScreenRe aderStopCo deLen = Le ngth(Scree nReaderSto pCode);
  199     ScreenRe aderStopCo deID = '-4 3';
  200     ScreenRe aderStopNa me = 'SCRE EN READER  STOP CODE  **';
  201     ScreenRe aderStopCo deLine = S creenReade rStopCodeI D + U + Sc reenReader StopName +  U + Scree nReaderCod eType;
  202     ScreenRe aderContin ueCode = S creenReade rCodeSigna ture + 'CO NT' + Temp lateFieldE ndSignatur e;
  203     ScreenRe aderContin ueCodeLen  = Length(S creenReade rContinueC ode);
  204     ScreenRe aderContin ueCodeOld  = ScreenRe aderCodeSi gnature +  'CONTINUE'  + Templat eFieldEndS ignature;
  205     ScreenRe aderContin ueCodeOldL en = Lengt h(ScreenRe aderContin ueCodeOld) ;
  206     ScreenRe aderContin ueCodeID =  '-44';
  207     ScreenRe aderContin ueCodeName  = 'SCREEN  READER CO NTINUE COD E ***';
  208     ScreenRe aderContin ueCodeLine  = ScreenR eaderConti nueCodeID  + U + Scre enReaderCo ntinueCode Name + U +  ScreenRea derCodeTyp e;
  209     MissingF ieldsTxt =  'One or m ore requir ed fields  must still  be entere d.';
  210  
  211     ScreenRe aderCodes:      array [0..Screen ReaderCode Count] of  string  =
  212         (Scr eenReaderS topCode, S creenReade rContinueC ode, Scree nReaderCon tinueCodeO ld);
  213     ScreenRe aderCodeLe ns:  array [0..Screen ReaderCode Count] of  integer =
  214         (Scr eenReaderS topCodeLen , ScreenRe aderContin ueCodeLen,  ScreenRea derContinu eCodeOldLe n);
  215     ScreenRe aderCodeID s:   array [0..Screen ReaderShow nCount] of  string  =
  216         (Scr eenReaderS topCodeID,  ScreenRea derContinu eCodeID);
  217     ScreenRe aderCodeLi nes: array [0..Screen ReaderShow nCount] of  string  =
  218         (Scr eenReaderS topCodeLin e, ScreenR eaderConti nueCodeLin e);
  219  
  220     Template FieldTypeC odes: arra y[TTemplat eFieldType ] of strin g =
  221                              {  df tUnknown       } ('',
  222                              {  df tEditBox       }  'E' ,
  223                              {  df tComboBox      }  'C' ,
  224                              {  df tButton        }  'B' ,
  225                              {  df tCheckBoxe s   }  'X' ,
  226                              {  df tRadioButt ons }  'R' ,
  227                              {  df tDate          }  'D' ,
  228                              {  df tNumber        }  'N' ,
  229                              {  df tHyperlink     }  'H' ,
  230                              {  df tWP            }  'W' ,
  231                              {  df tText          }  'T' ,
  232                              {  df tScreenRea der }  'S' );
  233  
  234     Template FieldTypeD esc: array [TTemplate FieldType,  boolean]  of string  =
  235                              {  df tUnknown       } (('' ,''),
  236                              {  df tEditBox       }  ('E dit Box',             'Edit'),
  237                              {  df tComboBox      }  ('C ombo Box',            'Combo'),
  238                              {  df tButton        }  ('B utton',               'Button'),
  239                              {  df tCheckBoxe s   }  ('C heck Boxes ',         'Check'),
  240                              {  df tRadioButt ons }  ('R adio Butto ns',       'Radio'),
  241                              {  df tDate          }  ('D ate',                 'Date'),
  242                              {  df tNumber        }  ('N umber',               'Num'),
  243                              {  df tHyperlink     }  ('H yperlink',            'Link'),
  244                              {  df tWP            }  ('W ord Proces sing',     'WP'),
  245                              {  df tText          }  ('D isplay Tex t',        'Text'),
  246                              {  df tScreenRea der }  ('S creen Read er Stop',  'SRStop')) ;
  247  
  248     Template DateTypeDe sc: array[ TTmplFldDa teType, bo olean] of  string =
  249                              { dtU nknown         } (('' ,''),
  250                              { dtD ate            }  ('D ate',            'Dat e'),
  251                              { dtD ateTime        }  ('D ate & Time ',    'Tim e'),
  252                              { dtD ateReqTime     }  ('D ate & Req  Time','R.T ime'),
  253                              { dtC ombo           }  ('D ate Combo' ,     'C.D ate'),
  254                              { dtY ear            }  ('Y ear',            'Yea r'),
  255                              { dtY earMonth       }  ('Y ear & Mont h',   'Mon th'));
  256  
  257     FldNames : array[TT emplateFie ldType] of  string =
  258                       {  dftUnknow n      }   ('',
  259                       {  dftEditBo x      }   'EDIT',
  260                       {  dftComboB ox     }   'LIST',
  261                       {  dftButton        }   'BTTN',
  262                       {  dftCheckB oxes   }   'CBOX',
  263                       {  dftRadioB uttons }   'RBTN',
  264                       {  dftDate          }   'DATE',
  265                       {  dftNumber        }   'NUMB',
  266                       {  dftHyperl ink    }   'LINK',
  267                       {  dftWP            }   'WRDP',
  268                       {  dftTExt          }   'TEXT',
  269                       {  dftScreen Reader }   'SRST');
  270  
  271     Template FieldDateC odes: arra y[TTmplFld DateType]  of string  =
  272                              { dtU nknown         } ('',
  273                              { dtD ate            }  'D' ,
  274                              { dtD ateTime        }  'T' ,
  275                              { dtD ateReqTime     }  'R' ,
  276                              { dtC ombo           }  'C' ,
  277                              { dtY ear            }  'Y' ,
  278                              { dtY earMonth       }  'M' );
  279  
  280     MaxTFWPL ines = 20;
  281     MaxTFEdt Len = 70;
  282  
  283   var
  284       MAX_WR AP_WIDTH:  integer =  MAX_ENTRY_ WIDTH;   / /MAX_WRAP_ WIDTH used  to set th e line wra p limit fo r template  field tex t
  285                                                        / /Consults  requires 7 4 characte rs; 80 for  everythin g else
  286   implementa tion
  287  
  288   uses
  289     rTemplat es, ORCtrl s, mTempla teFieldBut ton, dShar ed, uCore,  rCore, Wi ndows,
  290     VAUtils,  VA508Acce ssibilityM anager, VA 508Accessi bilityRout er, System .UITypes,  System.Typ es,
  291     fTemplat eDialog, u RequiredFi eldsHighli ghter;
  292  
  293  
  294   const
  295     NewTempl ateField =  'NEW TEMP LATE FIELD ';
  296     Template FieldSigna tureLen =  length(Tem plateField BeginSigna ture);
  297     Template FieldSigna tureEndLen  = length( TemplateFi eldEndSign ature);
  298  
  299   var
  300     uTmplFld s: TList =  nil;
  301     uEntries : TStringL ist = nil;
  302  
  303     uNewTemp lateFieldI DCnt: long int = 0;
  304     uRadioGr oupIndex:  integer =  0;
  305  
  306     uInterna lFieldIDCo unt: integ er = 0;
  307  
  308  
  309  
  310   const
  311     FieldIDD elim = '`' ;
  312     FieldIDL en = 6;
  313     NewLine  = 'NL';
  314  
  315   function g etUTmplFld s:TList;    // - acce ss to temp late field s NSR20100 706 AA 201 5/10/07
  316   begin
  317     Result : = uTmplFld s;
  318   end;
  319  
  320   function G etNewField ID: string ;
  321   begin
  322     inc(uInt ernalField IDCount);
  323     Result : = IntToStr (uInternal FieldIDCou nt);
  324     Result : = FieldIDD elim +
  325                copy(Str ingOfChar( '0', Field IDLen-2) +  Result, l ength(Resu lt), Field IDLen-1);
  326   end;
  327  
  328   function G etDialogEn try(AParen t: TWinCon trol; AID,  AText: st ring): TTe mplateDial ogEntry;
  329   var
  330     idx: int eger;
  331  
  332   begin
  333     Result : = nil;
  334     if AID =  '' then e xit;
  335     if(not a ssigned(uE ntries)) t hen
  336       uEntri es := TStr ingList.Cr eate;
  337     idx := u Entries.In dexOf(AID) ;
  338     if(idx <  0) then
  339     begin
  340       Result  := TTempl ateDialogE ntry.Creat e(AParent,  AID, ATex t);
  341       uEntri es.AddObje ct(AID, Re sult);
  342     end
  343     else
  344       Result  := TTempl ateDialogE ntry(uEntr ies.Object s[idx]);
  345   end;
  346  
  347   procedure  FreeEntrie s(SL: TStr ings);
  348   var
  349     i, idx,  cnt: integ er;
  350  
  351   begin
  352     if(assig ned(uEntri es)) then
  353     begin
  354       for i  := SL.Coun t-1 downto  0 do
  355       begin
  356         idx  := uEntrie s.IndexOf( SL[i]);
  357         if(i dx >= 0) t hen
  358         begi n
  359           cn t := uEntr ies.Count;
  360           if (assigned( uEntries.O bjects[idx ])) then
  361           be gin
  362              TTemplateD ialogEntry (uEntries. Objects[id x]).AutoDe stroyOnPan elFree :=  FALSE;
  363              uEntries.O bjects[idx ].Free;
  364           en d;
  365           if  cnt = uEn tries.Coun t then
  366              uEntries.D elete(idx) ;
  367         end;
  368       end;
  369       if(uEn tries.Coun t = 0) the n
  370         uInt ernalField IDCount :=  0;
  371     end;
  372   end;
  373  
  374   procedure  AssignFiel dIDs(var T xt: string );
  375   var
  376     i: integ er;
  377  
  378   begin
  379     i := 0;
  380     while (i  < length( Txt)) do
  381     begin
  382       inc(i) ;
  383       if(cop y(Txt,i,Te mplateFiel dSignature Len) = Tem plateField BeginSigna ture) then
  384       begin
  385         inc( i,Template FieldSigna tureLen);
  386         if(i  < length( Txt)) and  (copy(Txt, i,1) <> Fi eldIDDelim ) then
  387         begi n
  388           in sert(GetNe wFieldID,  Txt, i);
  389           in c(i, Field IDLen);
  390         end;
  391       end;
  392     end;
  393   end;
  394  
  395   procedure  AssignFiel dIDs(SL: T Strings);
  396   var
  397     i: integ er;
  398     txt: str ing;
  399  
  400   begin
  401     for i :=  0 to SL.C ount-1 do
  402     begin
  403       txt :=  SL[i];
  404       Assign FieldIDs(t xt);
  405       SL[i]  := txt;
  406     end;
  407   end;
  408  
  409   procedure  WordWrapTe xt(var Txt : string);
  410   var
  411     TmpSL: T StringList ;
  412     i: integ er;
  413  
  414     function  WrappedTe xt(const S tr: string ): string;
  415     var
  416       i, i2,  j, k: int eger;
  417       Temp:  string;
  418  
  419     begin
  420       Temp : = Str;
  421       Result  := '';
  422       i2 :=  0;
  423  
  424       repeat
  425         i :=  pos(Templ ateFieldBe ginSignatu re, Temp);
  426  
  427         if i >0 then
  428           j  := pos(Tem plateField EndSignatu re, copy(T emp, i, Ma xInt))
  429         else
  430           j  := 0;
  431  
  432         if ( j > 0) the n
  433           be gin
  434           i2  := pos(Te mplateFiel dBeginSign ature, cop y(Temp, i+ TemplateFi eldSignatu reLen, Max Int));
  435           if  (i2 = 0)  then
  436              i2 := MaxI nt
  437           el se
  438              i2 := i +  TemplateFi eldSignatu reLen + i2  - 1;
  439           en d;
  440  
  441         if ( i>0) and ( j=0) then
  442           i  := 0;
  443  
  444         if ( i>0) and ( j>0) then
  445           if  (j > i2)  then
  446              begin
  447              Result :=  Result + c opy(Temp,  1, i2-1);
  448              delete(Tem p, 1, i2-1 );
  449              end
  450           el se
  451              begin
  452              for k := ( i+Template FieldSigna tureLen) t o (i+j-2)  do
  453                if Temp[ k]=' ' the n
  454                  Temp[k ]:= #1;
  455              i := i + j  - 1;
  456              Result :=  Result + c opy(Temp,1 ,i);
  457              delete(Tem p,1,i);
  458              end;
  459  
  460       until  (i = 0);
  461  
  462       Result  := Result  + Temp;
  463       Result  := WrapTe xt(Result,  #13#10, [ ' '], MAX_ WRAP_WIDTH );
  464       repeat
  465         i :=  pos(#1, R esult);
  466         if i  > 0 then
  467           Re sult[i] :=  ' ';
  468       until  i = 0;
  469     end;
  470  
  471   begin
  472     if lengt h(Txt) > M AX_WRAP_WI DTH then
  473     begin
  474       TmpSL  := TString List.Creat e;
  475       try
  476         TmpS L.Text :=  Txt;
  477         Txt  := '';
  478         for  i := 0 to  TmpSL.Coun t-1 do
  479         begi n
  480           if  Txt <> ''  then
  481              Txt := Txt  + CRLF;
  482           Tx t := Txt +  WrappedTe xt(TmpSL[i ]);
  483         end;
  484       finall y
  485         TmpS L.Free;
  486       end;
  487     end;
  488   end;
  489  
  490   function R esolveTemp lateFields (Text: str ing;
  491                                     AutoWrap:  boolean;
  492                                     Hidden: b oolean = F ALSE;
  493                                     IncludeEm bedded: bo olean = FA LSE;
  494                                     AutoWrapI ndent: Int eger = 0):  string;
  495   var
  496     flen, Ct rlID, i, j : integer;
  497     Entry: T TemplateDi alogEntry;
  498     iField,  Temp, NewT xt, Fld: s tring;
  499     FoundEnt ry: boolea n;
  500     TmplFld:  TTemplate Field;
  501     TempCopy : String;
  502  
  503     procedur e AddNewTx t;
  504     begin
  505       if(New Txt <> '')  then
  506       begin
  507         inse rt(StringO fChar('x', length(New Txt)), Tem p, i);
  508         inse rt(NewTxt,  Result, i );
  509         inc( i, length( NewTxt));
  510       end;
  511     end;
  512  
  513   begin
  514     if(not a ssigned(uE ntries)) t hen
  515       uEntri es := TStr ingList.Cr eate;
  516     Result : = Text;
  517     Temp :=  Text; // U se Temp to  allow tem plate fiel ds to cont ain other  template f ield refer ences
  518     repeat
  519       i := p os(Templat eFieldBegi nSignature , Temp);
  520       if(i >  0) then
  521       begin
  522         Ctrl ID := 0;
  523         if(c opy(Temp,  i + Templa teFieldSig natureLen,  1) = Fiel dIDDelim)  then
  524         begi n
  525           Ct rlID := St rToIntDef( copy(Temp,  i + Templ ateFieldSi gnatureLen  + 1, Fiel dIDLen-1),  0);
  526           de lete(Temp, i + Templa teFieldSig natureLen,  FieldIDLe n);
  527           de lete(Resul t,i + Temp lateFieldS ignatureLe n, FieldID Len);
  528         end;
  529         j :=  pos(Templ ateFieldEn dSignature , copy(Tem p, i + Tem plateField SignatureL en, MaxInt ));
  530         Fld  := '';
  531         if(j  > 0) then
  532         begi n
  533           in c(j, i + T emplateFie ldSignatur eLen - 1);
  534           fl en := j -  i - Templa teFieldSig natureLen;
  535           Fl d := copy( Temp,i + T emplateFie ldSignatur eLen, flen );
  536           de lete(Temp, i,flen + T emplateFie ldSignatur eLen + 1);
  537           de lete(Resul t,i,flen +  TemplateF ieldSignat ureLen + 1 );
  538         end
  539         else
  540         begi n
  541           de lete(Temp, i,Template FieldSigna tureLen);
  542           de lete(Resul t,i,Templa teFieldSig natureLen) ;
  543         end;
  544         if(C trlID > 0)  then
  545         begi n
  546           Fo undEntry : = FALSE;
  547           fo r j := 0 t o uEntries .Count-1 d o
  548           be gin
  549              Entry := T TemplateDi alogEntry( uEntries.O bjects[j]) ;
  550              if(assigne d(Entry))  then
  551              begin
  552                if Inclu deEmbedded  then
  553                  iField  := Fld
  554                else
  555                  iField  := '';
  556                TempCopy  := copy(T emp, 1, i  - 1);
  557                if POS(C RLF, TempC opy) > 0 t hen
  558                  TempCo py := Copy (TempCopy,  LastDelim iter(CRLF,  TempCopy)  + 1, i);
  559  
  560                NewTxt : = Entry.Ge tControlTe xt(CtrlID,  FALSE, Fo undEntry,  AutoWrap,  iField, Te mpCopy, Au toWrapInde nt);
  561                TmplFld  := GetTemp lateField( Fld, FALSE );
  562                if (assi gned(TmplF ld)) and ( TmplFld.Da teType in  DateComboT ypes) then  {if this  is a TORDa teBox}
  563                   NewTx t := Piece (NewTxt,': ',1);           {we o nly want t he first p iece of Ne wTxt}
  564                AddNewTx t;
  565              end;
  566              if FoundEn try then b reak;
  567           en d;
  568           if  Hidden an d (not Fou ndEntry) a nd (Fld <>  '') then
  569           be gin
  570              NewTxt :=  TemplateFi eldBeginSi gnature +  Fld + Temp lateFieldE ndSignatur e;
  571              AddNewTxt;
  572           en d;
  573         end;
  574       end;
  575     until(i  = 0);
  576     if not A utoWrap th en
  577       WordWr apText(Res ult);
  578   end;
  579  
  580   function A reTemplate FieldsRequ ired(const  Text: str ing; FldVa lues: TORS tringList  =  nil): b oolean;
  581   var
  582     flen, Ct rlID, i, j : integer;
  583     Entry: T TemplateDi alogEntry;
  584     Fld: TTe mplateFiel d;
  585     Temp, Ne wTxt, FldN ame: strin g;
  586     FoundEnt ry: boolea n;
  587  
  588   begin
  589     if(not a ssigned(uE ntries)) t hen
  590       uEntri es := TStr ingList.Cr eate;
  591     Temp :=  Text;
  592     Result : = FALSE;
  593     repeat
  594       i := p os(Templat eFieldBegi nSignature , Temp);
  595       if(i >  0) then
  596       begin
  597         Ctrl ID := 0;
  598         if(c opy(Temp,  i + Templa teFieldSig natureLen,  1) = Fiel dIDDelim)  then
  599         begi n
  600           Ct rlID := St rToIntDef( copy(Temp,  i + Templ ateFieldSi gnatureLen  + 1, Fiel dIDLen-1),  0);
  601           de lete(Temp, i + Templa teFieldSig natureLen,  FieldIDLe n);
  602         end;
  603         j :=  pos(Templ ateFieldEn dSignature , copy(Tem p, i + Tem plateField SignatureL en, MaxInt ));
  604         if(j  > 0) then
  605         begi n
  606           in c(j, i + T emplateFie ldSignatur eLen - 1);
  607           fl en := j -  i - Templa teFieldSig natureLen;
  608           Fl dName := c opy(Temp,  i + Templa teFieldSig natureLen,  flen);
  609           Fl d := GetTe mplateFiel d(FldName,  FALSE);
  610           de lete(Temp, i,flen + T emplateFie ldSignatur eLen + 1);
  611         end
  612         else
  613         begi n
  614           de lete(Temp, i,Template FieldSigna tureLen);
  615           Fl d := nil;
  616         end;
  617         if(C trlID > 0)  and (assi gned(Fld))  and (Fld. Required)  then
  618         begi n
  619           Fo undEntry : = FALSE;
  620           fo r j := 0 t o uEntries .Count-1 d o
  621           be gin
  622              Entry := T TemplateDi alogEntry( uEntries.O bjects[j]) ;
  623              if(assigne d(Entry))  then
  624              begin
  625                NewTxt : = Entry.Ge tControlTe xt(CtrlID,  TRUE, Fou ndEntry, F ALSE);
  626                  if FoundEn try and (N ewTxt = '' ) then{(Tr im(NewTxt)  = '') the n //CODE A DDED BACK  IN -  DN S      BELLC}
  627                  Result  := True;
  628              end;
  629              if FoundEn try then b reak;
  630           en d;
  631           if  (not Foun dEntry) an d assigned (FldValues ) then
  632           be gin
  633              j := FldVa lues.Index OfPiece(In tToStr(Ctr lID));
  634              if(j < 0)  or (Piece( FldValues[ j],U,2) =  '') then
  635                Result : = TRUE;
  636           en d;
  637         end;
  638       end;
  639     until((i  = 0) or R esult);
  640   end;
  641  
  642   function H asTemplate Field(txt:  string):  boolean;
  643   begin
  644     Result : = (pos(Tem plateField BeginSigna ture, txt)  > 0);
  645   end;
  646  
  647   function G etTemplate Field(ATem plateField : string;  ByIEN: boo lean): TTe mplateFiel d;
  648   var
  649     i, idx:  integer;
  650     aData: T StringList ;
  651   begin
  652     Result : = nil;
  653     if(not a ssigned(uT mplFlds))  then
  654       uTmplF lds := TLi st.Create;
  655     idx := - 1;
  656     for i :=  0 to uTmp lFlds.Coun t-1 do
  657     begin
  658       if(ByI EN) then
  659       begin
  660         if(T TemplateFi eld(uTmplF lds[i]).FI D = ATempl ateField)  then
  661         begi n
  662           id x := i;
  663           br eak;
  664         end;
  665       end
  666       else
  667       begin
  668         if(T TemplateFi eld(uTmplF lds[i]).FF ldName = A TemplateFi eld) then
  669         begi n
  670           id x := i;
  671           br eak;
  672         end;
  673       end;
  674     end;
  675     if(idx <  0) then
  676     begin
  677         ADat a := TStri ngList.Cre ate;
  678         try
  679       if(ByI EN) then
  680              LoadTempla teFieldByI EN(ATempla teField, a Data)
  681       else
  682              LoadTempla teField(AT emplateFie ld, AData) ;
  683       if(ADa ta.Count >  1) then
  684         Resu lt := TTem plateField .Create(AD ata);
  685         fina lly
  686           Fr eeAndNil(A Data);
  687         end;
  688     end
  689     else
  690       Result  := TTempl ateField(u TmplFlds[i dx]);
  691   end;
  692  
  693   function T emplateFie ldNameProb lem(Fld: T TemplateFi eld): bool ean;
  694   const
  695     DUPFLD =  'Field Na me is not  unique';
  696  
  697   var
  698     i: integ er;
  699     msg: str ing;
  700  
  701   begin
  702     msg := ' ';
  703     if(Fld.F ldName = N ewTemplate Field) the n
  704       msg :=  'Field Na me can not  be ' + Ne wTemplateF ield
  705     else
  706     if(lengt h(Fld.FldN ame) < 3)  then
  707       msg :=  'Field Na me must be  at least  three char acters in  length'
  708     else
  709     if(not C harInSet(F ld.FldName [1], ['A'. .'Z','0'.. '9'])) the n
  710       msg :=  'First Fi eld Name c haracter m ust be "A"  - "Z", or  "0" - "9" '
  711     else
  712     if(assig ned(uTmplF lds)) then
  713     begin
  714       for i  := 0 to uT mplFlds.Co unt-1 do
  715       begin
  716         if(F ld <> uTmp lFlds[i])  and
  717           (C ompareText (TTemplate Field(uTmp lFlds[i]). FFldName,  Fld.FFldNa me) = 0) t hen
  718         begi n
  719           ms g := DUPFL D;
  720           br eak;
  721         end;
  722       end;
  723     end;
  724     if(msg =  '') and ( not IsTemp lateFieldN ameUnique( Fld.FFldNa me, Fld.ID )) then
  725       msg :=  DUPFLD;
  726     Result : = (msg <>  '');
  727     if(Resul t) then
  728       ShowMs g(msg);
  729   end;
  730  
  731   function S aveTemplat eFieldErro rs: string ;
  732   var
  733     i: integ er;
  734     Errors:  TStringLis t;
  735     Fld: TTe mplateFiel d;
  736     msg: str ing;
  737  
  738   begin
  739     Result : = '';
  740     if(assig ned(uTmplF lds)) then
  741     begin
  742       Errors  := nil;
  743       try
  744         for  i := 0 to  uTmplFlds. Count-1 do
  745         begi n
  746           Fl d := TTemp lateField( uTmplFlds[ i]);
  747           if (Fld.FModi fied) then
  748           be gin
  749              msg := Fld .SaveError ;
  750              if(msg <>  '') then
  751              begin
  752                if(not a ssigned(Er rors)) the n
  753                begin
  754                  Errors  := TStrin gList.Crea te;
  755                  Errors .Add('The  following  template f ield save  errors hav e occurred :');
  756                  Errors .Add('');
  757                end;
  758                Errors.A dd('  ' +  Fld.FldNam e + ': ' +  msg);
  759              end;
  760           en d;
  761         end;
  762       finall y
  763         if(a ssigned(Er rors)) the n
  764         begi n
  765           Re sult := Er rors.Text;
  766           Er rors.Free;
  767         end;
  768       end;
  769     end;
  770   end;
  771  
  772   procedure  ClearModif iedTemplat eFields;
  773   var
  774     i: integ er;
  775     Fld: TTe mplateFiel d;
  776  
  777   begin
  778     if(assig ned(uTmplF lds)) then
  779     begin
  780       for i  := uTmplFl ds.Count-1  downto 0  do
  781       begin
  782         Fld  := TTempla teField(uT mplFlds[i] );
  783         if(a ssigned(Fl d)) and (F ld.FModifi ed) then
  784         begi n
  785           if  Fld.FLock ed then
  786              UnlockTemp lateField( Fld.FID);
  787           Fl d.Free;
  788         end;
  789       end;
  790     end;
  791   end;
  792  
  793   function A nyTemplate FieldsModi fied: bool ean;
  794   var
  795     i: integ er;
  796  
  797   begin
  798     Result : = FALSE;
  799     if(assig ned(uTmplF lds)) then
  800     begin
  801       for i  := 0 to uT mplFlds.Co unt-1 do
  802       begin
  803         if(T TemplateFi eld(uTmplF lds[i]).FM odified) t hen
  804         begi n
  805           Re sult := TR UE;
  806           br eak;
  807         end;
  808       end;
  809     end;
  810   end;
  811  
  812   procedure  ListTempla teFields(c onst AText : string;  AList: TSt rings; Lis tErrors: b oolean = F ALSE);
  813   var
  814     i, j, k,  flen, Bad Count: int eger;
  815     flddesc,  tmp, fld:  string;
  816     TmpList:  TStringLi st;
  817     Inactive List: TStr ingList;
  818     FldObj:  TTemplateF ield;
  819  
  820   begin
  821     if(AText  = '') the n exit;
  822     BadCount  := 0;
  823     Inactive List := TS tringList. Create;
  824     try
  825       TmpLis t := TStri ngList.Cre ate;
  826       try
  827         TmpL ist.Text : = AText;
  828         for  k := 0 to  TmpList.Co unt-1 do
  829         begi n
  830           tm p := TmpLi st[k];
  831           re peat
  832              i := pos(T emplateFie ldBeginSig nature, tm p);
  833              if(i > 0)  then
  834              begin
  835                fld := ' ';
  836                j := pos (TemplateF ieldEndSig nature, co py(tmp, i  + Template FieldSigna tureLen, M axInt));
  837                if(j > 0 ) then
  838                begin
  839                  inc(j,  i + Templ ateFieldSi gnatureLen  - 1);
  840                  flen : = j - i -  TemplateFi eldSignatu reLen;
  841                  fld :=  copy(tmp, i + Templa teFieldSig natureLen,  flen);
  842                  delete (tmp, i, f len + Temp lateFieldS ignatureLe n + 1);
  843                end
  844                else
  845                begin
  846                  delete (tmp,i,Tem plateField SignatureL en);
  847                  inc(Ba dCount);
  848                end;
  849                if(fld < > '') then
  850                begin
  851                  if Lis tErrors th en
  852                  begin
  853                    FldO bj := GetT emplateFie ld(fld, FA LSE);
  854                    if a ssigned(Fl dObj) then
  855                    begi n
  856                      if  FldObj.In active the n
  857                         InactiveLi st.Add('   "' + fld +  '"');
  858                      fl ddesc := ' ';
  859                    end
  860                    else
  861                      fl ddesc := '   "' + fld  + '"';
  862                  end
  863                  else
  864                    fldd esc := fld ;
  865                  if(fld desc <> '' ) and (ALi st.IndexOf (flddesc)  < 0) then
  866                    ALis t.Add(fldd esc)
  867                end;
  868              end;
  869           un til (i = 0 );
  870         end;
  871       finall y
  872         TmpL ist.Free;
  873       end;
  874       if Lis tErrors th en
  875       begin
  876         if(A List.Count  > 0) then
  877           AL ist.Insert (0, 'The f ollowing t emplate fi elds were  not found: ');
  878         if ( BadCount >  0) then
  879         begi n
  880           if (BadCount  = 1) then
  881              tmp := 'A  template f ield marke r "' + Tem plateField BeginSigna ture +
  882                     '"  was found  without a'
  883           el se
  884              tmp := Int ToStr(BadC ount) + '  template f ield marke rs "' + Te mplateFiel dBeginSign ature +
  885                     '"  were found  without';
  886           if (AList.Cou nt > 0) th en
  887              AList.Add( '');
  888           AL ist.Add(tm p + ' matc hing "' +  TemplateFi eldEndSign ature + '" ');
  889         end;
  890         if(I nactiveLis t.Count >  0) then
  891         begi n
  892           if (AList.Cou nt > 0) th en
  893              AList.Add( '');
  894           AL ist.Add('T he followi ng inactiv e template  fields we re found:' );
  895           Fa stAddStrin gs(Inactiv eList, ALi st);
  896         end;
  897         if(A List.Count  > 0) then
  898         begi n
  899           AL ist.Insert (0, 'Text  contains t emplate fi eld errors :');
  900           AL ist.Insert (1, '');
  901         end;
  902       end;
  903     finally
  904       Inacti veList.Fre e;
  905     end;
  906   end;
  907  
  908   function B oilerplate TemplateFi eldsOK(con st AText:  string; Ms g: string  = ''): boo lean;
  909   var
  910     Errors:  TStringLis t;
  911     btns: TM sgDlgButto ns;
  912  
  913   begin
  914     Result : = TRUE;
  915     Errors : = TStringL ist.Create ;
  916     try
  917       ListTe mplateFiel ds(AText,  Errors, TR UE);
  918       if(Err ors.Count  > 0) then
  919       begin
  920         if(M sg = 'OK')  then
  921           bt ns := [mbO K]
  922         else
  923         begi n
  924           bt ns := [mbA bort, mbIg nore];
  925           Er rors.Add(' ');
  926           if (Msg = '')  then
  927              Msg := 'te xt inserti on';
  928           Er rors.Add(' Do you wan t to Abort  ' + Msg +  ', or Ign ore the er ror and co ntinue?');
  929         end;
  930         Resu lt := (Mes sageDlg(Er rors.Text,  mtError,  btns, 0) =  mrIgnore) ;
  931       end;
  932     finally
  933       Errors .Free;
  934     end;
  935   end;
  936  
  937   procedure  EnsureText (edt: TEdi t; ud: TUp Down);
  938   var
  939     v: integ er;
  940     s: strin g;
  941  
  942   begin
  943     if assig ned(ud.Ass ociate) th en
  944     begin
  945       v := S trToIntDef (edt.Text,  ud.Positi on);
  946       if (v  < ud.Min)  or (v > ud .Max) then
  947         v :=  ud.Positi on;
  948       s := I ntToStr(v) ;
  949       if edt .Text <> s  then
  950         edt. Text := s;
  951     end;
  952     edt.SelS tart := ed t.GetTextL en;    
  953   end;
  954  
  955   function T emplateFie ldCode2Fie ld(const C ode: strin g): TTempl ateFieldTy pe;
  956   var
  957     typ: TTe mplateFiel dType;
  958  
  959   begin
  960     Result : = dftUnkno wn;
  961     for typ  := low(TTe mplateFiel dType) to  high(TTemp lateFieldT ype) do
  962       if Cod e = Templa teFieldTyp eCodes[typ ] then
  963       begin
  964         Resu lt := typ;
  965         brea k;
  966       end;
  967   end;
  968  
  969   function T emplateDat eCode2Date Type(const  Code: str ing): TTmp lFldDateTy pe;
  970   var
  971     typ: TTm plFldDateT ype;
  972  
  973   begin
  974     Result : = dtUnknow n;
  975     for typ  := low(TTm plFldDateT ype) to hi gh(TTmplFl dDateType)  do
  976       if Cod e = Templa teFieldDat eCodes[typ ] then
  977       begin
  978         Resu lt := typ;
  979         brea k;
  980       end;
  981   end;
  982  
  983   procedure  ConvertCod es2Text(sl : TStrings ; Short: b oolean);
  984   var
  985     i: integ er;
  986     tmp, out put: strin g;
  987     ftype: T TemplateFi eldType;
  988     dtype: T TmplFldDat eType;
  989  
  990   begin
  991     for i :=  0 to sl.C ount-1 do
  992     begin
  993       tmp :=  sl[i];
  994       if pie ce(tmp,U,4 ) = BOOLCH AR[TRUE] t hen
  995         outp ut := '* '
  996       else
  997         outp ut := '  ' ;
  998       ftype  := Templat eFieldCode 2Field(Pie ce(tmp, U,  3));
  999       if fty pe = dftDa te then
  1000       begin
  1001         dtyp e := Templ ateDateCod e2DateType (Piece(tmp , U, 5));
  1002         outp ut := outp ut + Templ ateDateTyp eDesc[dtyp e, short];
  1003       end
  1004       else
  1005         outp ut := outp ut + Templ ateFieldTy peDesc[fty pe, short] ;
  1006       SetPie ce(tmp, U,  3, output );
  1007       sl[i]  := tmp;
  1008     end;
  1009   end;
  1010  
  1011   { TTemplat eField }
  1012  
  1013   constructo r TTemplat eField.Cre ate(AData:  TStrings) ;
  1014   var
  1015     tmp, p1:  string;
  1016     AFID, i, idx,cnt: i nteger;
  1017  
  1018   begin
  1019     AFID :=  0;
  1020     if(assig ned(AData) ) then
  1021     begin
  1022       if ADa ta.Count >  0 then
  1023         AFID  := StrToI ntDef(ADat a[0],0);
  1024       if(AFI D > 0) and  (AData.Co unt > 1) t hen
  1025       begin
  1026         FID  := IntToSt r(AFID);
  1027         FFld Name := Pi ece(AData[ 1],U,1);
  1028         FFld Type := Te mplateFiel dCode2Fiel d(Piece(AD ata[1],U,2 ));
  1029         FIna ctive := ( Piece(ADat a[1],U,3)  = '1');
  1030         FMax Len := Str ToIntDef(P iece(AData [1],U,4),0 );
  1031         FEdi tDefault : = Piece(AD ata[1],U,5 );
  1032         FLMT ext := Pie ce(AData[1 ],U,6);
  1033         idx  := StrToIn tDef(Piece (AData[1], U,7),0);
  1034         cnt  := 0;
  1035         for  i := 2 to  AData.Coun t-1 do
  1036         begi n
  1037           tm p := AData [i];
  1038           p1  := Piece( tmp,U,1);
  1039           tm p := Piece (tmp,U,2);
  1040           if (p1 = 'D')  then
  1041              FNotes :=  FNotes + t mp + CRLF
  1042           el se
  1043           if (p1 = 'U')  then
  1044              FURL := tm p
  1045           el se
  1046           if (p1 = 'I')  then
  1047           be gin
  1048              inc(cnt);
  1049              FItems :=  FItems + t mp + CRLF;
  1050              if(cnt=idx ) then
  1051                FItemDef ault := tm p;
  1052           en d;
  1053         end;
  1054         FReq uired  :=  (Piece(ADa ta[1],U,8)  = '1');
  1055         FSep Lines  :=  (Piece(ADa ta[1],U,9)  = '1');
  1056         FTex tLen   :=  StrToIntDe f(Piece(AD ata[1],U,1 0),0);
  1057         FInd ent    :=  StrToIntDe f(Piece(AD ata[1],U,1 1),0);
  1058         FPad        :=  StrToIntDe f(Piece(AD ata[1],U,1 2),0);
  1059         FMin Val    :=  StrToIntDe f(Piece(AD ata[1],U,1 3),0);
  1060         FMax Val    :=  StrToIntDe f(Piece(AD ata[1],U,1 4),0);
  1061         FInc rement :=  StrToIntDe f(Piece(AD ata[1],U,1 5),0);
  1062         FDat eType  :=  TemplateDa teCode2Dat eType(Piec e(AData[1] ,U,16));
  1063         FCom munityCare  := (Piece (AData[1], U,17) = '1 ');
  1064         FMod ified  :=  FALSE;
  1065         FNam eChanged : = FALSE;
  1066       end;
  1067     end;
  1068     if(AFID  = 0) then
  1069     begin
  1070       inc(uN ewTemplate FieldIDCnt );
  1071       FID :=  IntToStr( -uNewTempl ateFieldID Cnt);
  1072       FFldNa me := NewT emplateFie ld;
  1073       FModif ied := TRU E;
  1074     end;
  1075     if(not a ssigned(uT mplFlds))  then
  1076       uTmplF lds := TLi st.Create;
  1077     uTmplFld s.Add(Self );
  1078   end;
  1079  
  1080   function T TemplateFi eld.GetTem plateField Default: s tring;
  1081   begin
  1082       case F FldType of
  1083         dftE ditBox, df tNumber:   Result :=  FEditDefau lt;
  1084  
  1085         dftC omboBox,
  1086         dftB utton,
  1087         dftC heckBoxes,            {Clear out  embedded  fields}
  1088         dftR adioButton s:         Result :=  StripEmbed ded(FItemD efault);
  1089  
  1090         dftD ate:                  if FEditDe fault <> ' ' then Res ult := FEd itDefault;
  1091  
  1092         dftH yperlink,  dftText:   if FEditDe fault <> ' ' then
  1093                                       Result  := StripEm bedded(FEd itDefault)
  1094                                    else
  1095                                       Result  := URL;
  1096  
  1097         dftW P:                    Result :=  Items;
  1098       end;
  1099   end;
  1100  
  1101   procedure  TTemplateF ield.Creat eDialogCon trols(Entr y: TTempla teDialogEn try;
  1102                                           var  Index: In teger; Ctr lID: integ er);
  1103  
  1104   var
  1105     i, Aht,  w, tmp, AW dth: integ er;
  1106     STmp: st ring;
  1107     TmpSL: T StringList ;
  1108     edt: TEd it;
  1109     cbo: TOR ComboBox;
  1110     cb: TORC heckBox;
  1111     btn: Tfr aTemplateF ieldButton ;
  1112     dbox: TO RDateBox;
  1113     dcbo: TO RDateCombo ;
  1114     lbl: TCP RSTemplate FieldLabel ;
  1115     re: TRic hEdit;
  1116     pnl: TCP RSDialogNu mber;
  1117     DefDate:  TFMDateTi me;
  1118     ctrl: TC ontrol;
  1119  
  1120     function  wdth: int eger;
  1121     begin
  1122       if(Awd th < 0) th en
  1123         Awdt h := FontW idthPixel( Entry.FFon t.Handle);
  1124       Result  := Awdth;
  1125     end;
  1126  
  1127     function  ht: integ er;
  1128     begin
  1129       if(Aht  < 0) then
  1130         Aht  := FontHei ghtPixel(E ntry.FFont .Handle);
  1131       Result  := Aht;
  1132     end;
  1133  
  1134     procedur e UpdateIn dents(ACon trol: TCon trol);
  1135     var
  1136       idx: i nteger;
  1137  
  1138     begin
  1139       if (FI ndent > 0)  or (FPad  > 0) then
  1140       begin
  1141         idx  := Entry.F Indents.In dexOfObjec t(AControl );
  1142         if i dx < 0 the n
  1143           En try.FInden ts.AddObje ct(IntToSt r(FIndent  * wdth) +  U + IntToS tr(FPad),  AControl);
  1144       end;
  1145     end;
  1146  
  1147   begin
  1148     if(not F Inactive)  and (FFldT ype <> dft Unknown) t hen
  1149     begin
  1150       AWdth  := -1;
  1151       Aht :=  -1;
  1152       ctrl : = nil;
  1153  
  1154       case F FldType of
  1155         dftE ditBox:
  1156           be gin
  1157              edt := TCP RSDialogFi eldEdit.Cr eate(nil);
  1158              (edt as IC PRSDialogC omponent). RequiredFi eld := Req uired;
  1159              edt.Parent  := Entry. FPanel;
  1160              edt.Border Style := b sNone;
  1161              edt.Height  := ht;
  1162              edt.Width  := (wdth *  Width + 4 );
  1163              if FTextLe n > 0 then
  1164                edt.MaxL ength := F TextLen
  1165              else
  1166                edt.MaxL ength := F MaxLen;
  1167              edt.Text : = FEditDef ault;
  1168              edt.Tag :=  CtrlID;
  1169              edt.OnChan ge := Entr y.DoChange ;
  1170              UpdateColo rsFor508Co mpliance(e dt, TRUE);
  1171              ctrl := ed t;
  1172           en d;
  1173  
  1174         dftC omboBox:
  1175           be gin
  1176              cbo := TCP RSDialogCo mboBox.Cre ate(nil);
  1177              (cbo as IC PRSDialogC omponent). RequiredFi eld := Req uired;
  1178              cbo.Parent  := Entry. FPanel;
  1179              cbo.Templa teField :=  TRUE;
  1180              w := Width ;
  1181              cbo.MaxLen gth := w;
  1182              if FTextLe n > 0 then
  1183                cbo.MaxL ength := F TextLen
  1184              else
  1185                cbo.List ItemsOnly  := TRUE;
  1186              {Clear out  embedded  fields}
  1187              cbo.Items. Text := St ripEmbedde d(Items);
  1188              cbo.Select ByID(Strip Embedded(F ItemDefaul t));
  1189              cbo.Tag :=  CtrlID;
  1190              cbo.OnChan ge := Entr y.DoChange ;
  1191  
  1192              if cbo.Ite ms.Count >  12 then
  1193              begin
  1194                cbo.Widt h := (wdth  * w) + Sc rollBarWid th + 8;
  1195                cbo.Drop DownCount  := 12;
  1196              end
  1197              else
  1198              begin
  1199                cbo.Widt h := (wdth  * w) + 18 ;
  1200                cbo.Drop DownCount  := cbo.Ite ms.Count;
  1201              end;
  1202              UpdateColo rsFor508Co mpliance(c bo, TRUE);
  1203              ctrl := cb o;
  1204           en d;
  1205  
  1206         dftB utton:
  1207           be gin
  1208              btn := Tfr aTemplateF ieldButton .Create(ni l);
  1209              (btn as IC PRSDialogC omponent). RequiredFi eld := Req uired;
  1210              btn.Parent  := Entry. FPanel;
  1211              {Clear out  embedded  fields}
  1212              btn.Items. Text := St ripEmbedde d(Items);
  1213              btn.Button Text := St ripEmbedde d(FItemDef ault);
  1214              btn.Height  := ht;
  1215              btn.Width  := (wdth *  Width) +  6;
  1216              btn.Tag :=  CtrlID;
  1217              btn.OnChan ge := Entr y.DoChange ;
  1218              UpdateColo rsFor508Co mpliance(b tn);
  1219              ctrl := bt n;
  1220           en d;
  1221  
  1222         dftC heckBoxes,  dftRadioB uttons:
  1223           be gin
  1224              if FFldTyp e = dftRad ioButtons  then
  1225                inc(uRad ioGroupInd ex);
  1226              TmpSL := T StringList .Create;
  1227              try
  1228                {Clear o ut embedde d fields}
  1229                TmpSL.Te xt := Stri pEmbedded( Items);
  1230                for i :=  0 to TmpS L.Count-1  do
  1231                begin
  1232                  cb :=  TCPRSDialo gCheckBox. Create(nil );
  1233                  if i =  0 then
  1234                    (cb  as ICPRSDi alogCompon ent).Requi redField : = Required ;
  1235                  cb.Par ent := Ent ry.FPanel;
  1236                  cb.Cap tion := Tm pSL[i];
  1237                  cb.Aut oSize := T RUE;
  1238                  cb.Aut oAdjustSiz e;
  1239     //               cb .AutoSize  := FALSE;
  1240     //               cb .Height :=  ht;
  1241                  if FFl dType = df tRadioButt ons then
  1242                  begin
  1243                    cb.G roupIndex  := uRadioG roupIndex;
  1244                    cb.R adioStyle  := TRUE;
  1245                  end;
  1246                  if(Tmp SL[i] = St ripEmbedde d(FItemDef ault)) the n
  1247                    cb.C hecked :=  TRUE;
  1248                  cb.Tag  := CtrlID ;
  1249                  if FSe pLines and  (FFldType  in SepLin esTypes) t hen
  1250                    cb.S tringData  := NewLine ;
  1251                  cb.OnC lick := En try.DoChan ge;
  1252                  Update ColorsFor5 08Complian ce(cb);
  1253                  inc(In dex);
  1254                  Entry. FControls. InsertObje ct(Index,  '', cb);
  1255  
  1256                  AddFie ldControl( self,cb,In tToStr(ctr lID)); //  NSR2010070 6 AA 2015/ 10/09. Add ing Fld.FI D to track  Fld by co ntrol
  1257  
  1258                  if (i= 0) or FSep Lines then
  1259                    Upda teIndents( cb);
  1260                end;
  1261              finally
  1262                TmpSL.Fr ee;
  1263              end;
  1264           en d;
  1265  
  1266         dftD ate:
  1267           be gin
  1268              if FEditDe fault <> ' ' then
  1269                DefDate  := StrToFM DateTime(F EditDefaul t)
  1270              else
  1271                DefDate  := 0;
  1272              if FDateTy pe in Date ComboTypes  then
  1273              begin
  1274                dcbo :=  TCPRSDialo gDateCombo .Create(ni l);
  1275                (dcbo as  ICPRSDial ogComponen t).Require dField :=  Required;
  1276                dcbo.Par ent := Ent ry.FPanel;
  1277                dcbo.Tag  := CtrlID ;
  1278                dcbo.Inc ludeBtn :=  (FDateTyp e = dtComb o);
  1279                dcbo.Inc ludeDay :=  (FDateTyp e = dtComb o);
  1280                dcbo.Inc ludeMonth  := (FDateT ype <> dtY ear);
  1281                dcbo.FMD ate := Def Date;
  1282                dcbo.Tem plateField  := TRUE;
  1283                dcbo.OnC hange := E ntry.DoCha nge;
  1284                UpdateCo lorsFor508 Compliance (dcbo, TRU E);
  1285                ctrl :=  dcbo;
  1286              end
  1287              else
  1288              begin
  1289                dbox :=  TCPRSDialo gDateBox.C reate(nil) ;
  1290                (dbox as  ICPRSDial ogComponen t).Require dField :=  Required;
  1291                dbox.Par ent := Ent ry.FPanel;
  1292                dbox.Tag  := CtrlID ;
  1293                dbox.Dat eOnly := ( FDateType  = dtDate);
  1294                dbox.Req uireTime : = (FDateTy pe = dtDat eReqTime);
  1295                dbox.Tem plateField  := TRUE;
  1296                dbox.FMD ateTime :=  DefDate;
  1297                if (FDat eType = dt Date) then
  1298                  tmp :=  11
  1299                else
  1300                  tmp :=  17;
  1301                dbox.Wid th := (wdt h * tmp) +  18;
  1302                dbox.OnC hange := E ntry.DoCha nge;
  1303                UpdateCo lorsFor508 Compliance (dbox, TRU E);
  1304                ctrl :=  dbox;
  1305              end;
  1306           en d;
  1307  
  1308         dftN umber:
  1309           be gin
  1310              pnl := TCP RSDialogNu mber.Creat ePanel(nil );
  1311              (pnl as IC PRSDialogC omponent). RequiredFi eld := Req uired;
  1312              pnl.Parent  := Entry. FPanel;
  1313              pnl.BevelO uter := bv None;
  1314              pnl.Tag :=  CtrlID;
  1315              pnl.Edit.H eight := h t;
  1316              pnl.Edit.W idth := (w dth * 5 +  4);
  1317              pnl.UpDown .Min := Mi nVal;
  1318              pnl.UpDown .Max := Ma xVal;
  1319              pnl.UpDown .Min := Mi nVal; // B oth ud.Min  settings  are needee d!
  1320              i := Incre ment;
  1321              if i < 1 t hen i := 1 ;
  1322              pnl.UpDown .Increment  := i;
  1323              pnl.UpDown .Position  := StrToIn tDef(EditD efault, 0) ;
  1324              pnl.Edit.O nChange :=  Entry.UpD ownChange;
  1325              pnl.Height  := pnl.Ed it.Height;
  1326              pnl.Width  := pnl.Edi t.Width +  pnl.UpDown .Width;
  1327              UpdateColo rsFor508Co mpliance(p nl, TRUE);
  1328              //CQ 17597  wat
  1329              pnl.Edit.A lign := al Left;
  1330              pnl.UpDown .Align :=  alLeft;
  1331              //end 1759 7
  1332              ctrl := pn l;
  1333           en d;
  1334  
  1335         dftH yperlink,  dftText:
  1336           be gin
  1337              if (FFldTy pe = dftHy perlink) a nd User.We bAccess th en
  1338                lbl := T CPRSDialog HyperlinkL abel.Creat e(nil)
  1339              else
  1340                lbl := T CPRSTempla teFieldLab el.Create( nil);
  1341              lbl.Parent  := Entry. FPanel;
  1342              lbl.ShowAc celChar :=  FALSE;
  1343              lbl.Exclud e := FSepL ines;
  1344              if (FFldTy pe = dftHy perlink) t hen
  1345              begin
  1346                if FEdit Default <>  '' then
  1347                  lbl.Ca ption := S tripEmbedd ed(FEditDe fault)
  1348                else
  1349                  lbl.Ca ption := U RL;
  1350              end
  1351              else
  1352              begin
  1353                STmp :=  StripEmbed ded(Items) ;
  1354                if copy( STmp,lengt h(STmp)-1, 2) = CRLF  then
  1355                  delete (STmp,leng th(STmp)-1 ,2);
  1356                lbl.Capt ion := STm p;
  1357              end;
  1358              if lbl is  TCPRSDialo gHyperlink Label then
  1359                TCPRSDia logHyperli nkLabel(lb l).Init(FU RL);
  1360              lbl.Tag :=  CtrlID;
  1361              UpdateColo rsFor508Co mpliance(l bl);
  1362              ctrl := lb l;
  1363           en d;
  1364  
  1365         dftW P:
  1366           be gin
  1367              re := TCPR SDialogRic hEdit.Crea te(nil);
  1368              (re as ICP RSDialogCo mponent).R equiredFie ld := Requ ired;
  1369              re.Parent  := Entry.F Panel;
  1370              re.Tag :=  CtrlID;
  1371              tmp := FMa xLen;
  1372              if tmp < 5  then
  1373                tmp := 5 ;
  1374              re.Width : = wdth * t mp;
  1375              tmp := FTe xtLen;
  1376              if tmp < 2  then
  1377                tmp := 2
  1378              else
  1379              if tmp > M axTFWPLine s then
  1380                tmp := M axTFWPLine s;
  1381              re.Height  := ht * tm p;
  1382              re.BorderS tyle := bs None;
  1383              re.ScrollB ars := ssV ertical;
  1384              re.Lines.T ext := Ite ms;
  1385              re.OnChang e := Entry .DoChange;
  1386              UpdateColo rsFor508Co mpliance(r e, TRUE);
  1387              ctrl := re ;
  1388           en d;
  1389       end;
  1390       if ass igned(ctrl ) then
  1391       begin
  1392         inc( Index);
  1393         Entr y.FControl s.InsertOb ject(Index , '', ctrl );
  1394         addF ieldContro l(self,TWi nControl(c trl),IntTo Str(ctrlID )); // NSR 20100706   AA 2015/10 /09 adding  Fld.FID t o track Fl d by contr ol
  1395         Upda teIndents( ctrl);
  1396       end;
  1397     end;
  1398   end;
  1399  
  1400   function T TemplateFi eld.CanMod ify: boole an;
  1401   begin
  1402     if((not  FModified)  and (not  FLocked) a nd (StrToI ntDef(FID, 0) > 0)) t hen
  1403     begin
  1404       FLocke d := LockT emplateFie ld(FID);
  1405       Result  := FLocke d;
  1406       if(not  FLocked)  then
  1407         Show Msg('Templ ate Field  ' + FFldNa me + ' is  currently  being edit ed by anot her user.' );
  1408     end
  1409     else
  1410       Result  := TRUE;
  1411     if(Resul t) then FM odified :=  TRUE;
  1412   end;
  1413  
  1414   procedure  TTemplateF ield.SetEd itDefault( const Valu e: string) ;
  1415   begin
  1416     if(FEdit Default <>  Value) an d CanModif y then
  1417   // DRM - I 9259852FY1 6/529128 -  2017/7/21  - Restric t default  value to p rintable A SCII chara cters + TA B
  1418   //    FEdi tDefault : = Value;
  1419       FEditD efault :=  FilteredSt ring(Value );
  1420   // DRM - I 9259852FY1 6/529128 -  2017/7/21  ---
  1421   end;
  1422  
  1423   procedure  TTemplateF ield.SetFl dName(cons t Value: s tring);
  1424   begin
  1425     if(FFldN ame <> Val ue) and Ca nModify th en
  1426     begin
  1427       FFldNa me := Valu e;
  1428       FNameC hanged :=  TRUE;
  1429     end;
  1430   end;
  1431  
  1432   procedure  TTemplateF ield.SetFl dType(cons t Value: T TemplateFi eldType);
  1433   begin
  1434     if(FFldT ype <> Val ue) and Ca nModify th en
  1435     begin
  1436       FFldTy pe := Valu e;
  1437       if(Val ue = dftEd itBox) the n
  1438       begin
  1439         if ( FMaxLen <  1) then
  1440           FM axLen := 1 ;
  1441         if F TextLen <  FMaxLen th en
  1442           FT extLen :=  FMaxLen;
  1443       end
  1444       else
  1445       if(Val ue = dftHy perlink) a nd (FURL =  '') then
  1446         FURL  := 'http: //'
  1447       else
  1448       if(Val ue = dftCo mboBox) an d (FMaxLen  < 1) then
  1449       begin
  1450         FMax Len := Wid th;
  1451         if F MaxLen < 1  then
  1452           FM axLen := 1 ;
  1453       end
  1454       else
  1455       if(Val ue = dftWP ) then
  1456       begin
  1457         if ( FMaxLen =  0) then
  1458           FM axLen := M AX_WRAP_WI DTH
  1459         else
  1460         if ( FMaxLen <  5) then
  1461              FMaxLen :=  5;
  1462         if F TextLen <  2 then
  1463           FT extLen :=  2;
  1464       end
  1465       else
  1466       if(Val ue = dftDa te) and (F DateType =  dtUnknown ) then
  1467         FDat eType := d tDate;
  1468     end;
  1469   end;
  1470  
  1471   procedure  TTemplateF ield.SetID (const Val ue: string );
  1472   begin
  1473   //  if(FID  <> Value)  and CanMo dify then
  1474       FID :=  Value;
  1475   end;
  1476  
  1477   procedure  TTemplateF ield.SetIn active(con st Value:  boolean);
  1478   begin
  1479     if(FInac tive <> Va lue) and C anModify t hen
  1480       FInact ive := Val ue;
  1481   end;
  1482  
  1483   procedure  TTemplateF ield.SetIt emDefault( const Valu e: string) ;
  1484   begin
  1485     if(FItem Default <>  Value) an d CanModif y then
  1486       FItemD efault :=  Value;
  1487   end;
  1488  
  1489   procedure  TTemplateF ield.SetIt ems(const  Value: str ing);
  1490   begin
  1491     if(FItem s <> Value ) and CanM odify then
  1492       FItems  := Value;
  1493   end;
  1494  
  1495   procedure  TTemplateF ield.SetLM Text(const  Value: st ring);
  1496   begin
  1497     if(FLMTe xt <> Valu e) and Can Modify the n
  1498       FLMTex t := Value ;
  1499   end;
  1500  
  1501   procedure  TTemplateF ield.SetMa xLen(const  Value: in teger);
  1502   begin
  1503     if(FMaxL en <> Valu e) and Can Modify the n
  1504       FMaxLe n := Value ;
  1505   end;
  1506  
  1507   procedure  TTemplateF ield.SetNo tes(const  Value: str ing);
  1508   begin
  1509     if(FNote s <> Value ) and CanM odify then
  1510       FNotes  := Value;
  1511   end;
  1512  
  1513   function T TemplateFi eld.SaveEr ror: strin g;
  1514   var
  1515     TmpSL, F ldSL: TStr ingList;
  1516     AID,Res:  string;
  1517     idx, i:  integer;
  1518     IEN64: I nt64;
  1519     NewRec:  boolean;
  1520  
  1521   begin
  1522     if(FFldN ame = NewT emplateFie ld) then
  1523     begin
  1524       Result  := 'Templ ate Field  can not be  named "'  + NewTempl ateField +  '"';
  1525       exit;
  1526     end;
  1527     Result : = '';
  1528     NewRec : = (StrToIn tDef(FID,0 ) < 0);
  1529     if(FModi fied or Ne wRec) then
  1530     begin
  1531       TmpSL  := TString List.Creat e;
  1532       try
  1533         FldS L := TStri ngList.Cre ate;
  1534         try
  1535           if (StrToIntD ef(FID,0)  > 0) then
  1536              AID := FID
  1537           el se
  1538              AID := '0' ;
  1539           Fl dSL.Add('. 01='+FFldN ame);
  1540           Fl dSL.Add('. 02='+Templ ateFieldTy peCodes[FF ldType]);
  1541           Fl dSL.Add('. 03='+BOOLC HAR[FInact ive]);
  1542           Fl dSL.Add('. 04='+IntTo Str(FMaxLe n));
  1543           Fl dSL.Add('. 05='+FEdit Default);
  1544           Fl dSL.Add('. 06='+FLMTe xt);
  1545           id x := -1;
  1546           if (FItems <>  '') and ( FItemDefau lt <> '')  then
  1547           be gin
  1548              TmpSL.Text  := FItems ;
  1549              for i := 0  to TmpSL. Count-1 do
  1550                if(FItem Default =  TmpSL[i])  then
  1551                begin
  1552                  idx :=  i;
  1553                  break;
  1554                end;
  1555           en d;
  1556           Fl dSL.Add('. 07='+IntTo Str(Idx+1) );
  1557           Fl dSL.Add('. 08='+BOOLC HAR[fRequi red]);
  1558           Fl dSL.Add('. 09='+BOOLC HAR[fSepLi nes]);
  1559           Fl dSL.Add('. 1=' +IntTo Str(FTextL en));
  1560           Fl dSL.Add('. 11='+IntTo Str(FInden t));
  1561           Fl dSL.Add('. 12='+IntTo Str(FPad)) ;
  1562           Fl dSL.Add('. 13='+IntTo Str(FMinVa l));
  1563           Fl dSL.Add('. 14='+IntTo Str(FMaxVa l));
  1564           Fl dSL.Add('. 15='+IntTo Str(FIncre ment));
  1565           if  FDateType  = dtUnkno wn then
  1566              FldSL.Add( '.16=@')
  1567           el se
  1568              FldSL.Add( '.16='+Tem plateField DateCodes[ FDateType] );
  1569  
  1570           if  FURL='' t hen
  1571              FldSL.Add( '3=@')
  1572           el se
  1573              FldSL.Add( '3='+FURL) ;
  1574  
  1575           if (FNotes <>  '') or (n ot NewRec)  then
  1576           be gin
  1577              if(FNotes  = '') then
  1578                FldSL.Ad d('2,1=@')
  1579              else
  1580              begin
  1581                TmpSL.Te xt := FNot es;
  1582                for i :=  0 to TmpS L.Count-1  do
  1583                  FldSL. Add('2,'+I ntToStr(i+ 1)+',0='+T mpSL[i]);
  1584              end;
  1585           en d;
  1586           if ((FItems < > '') or ( not NewRec )) then
  1587           be gin
  1588              if(FItems  = '') then
  1589                FldSL.Ad d('10,1=@' )
  1590              else
  1591              begin
  1592                TmpSL.Te xt := FIte ms;
  1593                for i :=  0 to TmpS L.Count-1  do
  1594                  FldSL. Add('10,'+ IntToStr(i +1)+',0='+ TmpSL[i]);
  1595              end;
  1596           en d;
  1597  
  1598           Re s := Updat eTemplateF ield(AID,  FldSL);
  1599           IE N64 := Str ToInt64Def (Piece(Res ,U,1),0);
  1600           if (IEN64 > 0 ) then
  1601           be gin
  1602              if(NewRec)  then
  1603                FID := I ntToStr(IE N64)
  1604              else
  1605                UnlockTe mplateFiel d(FID);
  1606              FModified  := FALSE;
  1607              FNameChang ed := FALS E;
  1608              FLocked :=  FALSE;
  1609           en d
  1610           el se
  1611              Result :=  Piece(Res,  U, 2);
  1612         fina lly
  1613           Fl dSL.Free;
  1614         end;
  1615       finall y
  1616         TmpS L.Free;
  1617       end;
  1618     end;
  1619   end;
  1620  
  1621   procedure  TTemplateF ield.Assig n(AFld: TT emplateFie ld);
  1622   begin
  1623     FMaxLen         :=  AFld.FMaxL en;
  1624     FFldName        :=  AFld.FFldN ame;
  1625     FLMText         :=  AFld.FLMTe xt;
  1626     FEditDef ault   :=  AFld.FEdit Default;
  1627     FNotes          :=  AFld.FNote s;
  1628     FItems          :=  AFld.FItem s;
  1629     FInactiv e      :=  AFld.FInac tive;
  1630     FItemDef ault   :=  AFld.FItem Default;
  1631     FFldType        :=  AFld.FFldT ype;
  1632     FRequire d      :=  AFld.FRequ ired;
  1633     FSepLine s      :=  AFld.FSepL ines;
  1634     FTextLen        :=  AFld.FText Len;
  1635     FIndent         :=  AFld.FInde nt;
  1636     FPad            :=  AFld.FPad;
  1637     FMinVal         :=  AFld.FMinV al;
  1638     FMaxVal         :=  AFld.FMaxV al;
  1639     FIncreme nt     :=  AFld.FIncr ement;
  1640     FDateTyp e      :=  AFld.FDate Type;
  1641     FURL            :=  AFld.FURL;
  1642     FCommuni tyCare :=  AFld.FComm unityCare;
  1643   end;
  1644  
  1645   function T TemplateFi eld.Width:  integer;
  1646   var
  1647     i, ilen:  integer;
  1648     TmpSL: T StringList ;
  1649  
  1650   begin
  1651     if(FFldT ype = dftE ditBox) th en
  1652       Result  := FMaxLe n
  1653     else
  1654     begin
  1655       if FMa xLen > 0 t hen
  1656         Resu lt := FMax Len
  1657       else
  1658       begin
  1659         Resu lt := -1;
  1660         TmpS L := TStri ngList.Cre ate;
  1661         try
  1662           Tm pSL.Text : = StripEmb edded(FIte ms);
  1663           fo r i := 0 t o TmpSL.Co unt-1 do
  1664           be gin
  1665              ilen := le ngth(TmpSL [i]);
  1666              if(Result  < ilen) th en
  1667                Result : = ilen;
  1668           en d;
  1669         fina lly
  1670           Tm pSL.Free;
  1671         end;
  1672       end;
  1673     end;
  1674     if Resul t > MaxTFE dtLen then
  1675       Result  := MaxTFE dtLen;
  1676   end;
  1677  
  1678   destructor  TTemplate Field.Dest roy;
  1679   begin
  1680     uTmplFld s.Remove(S elf);
  1681     inherite d;
  1682   end;
  1683  
  1684   procedure  TTemplateF ield.SetRe quired(con st Value:  boolean);
  1685   begin
  1686     if(FRequ ired <> Va lue) and C anModify t hen
  1687       FRequi red := Val ue;
  1688   end;
  1689  
  1690   function T TemplateFi eld.NewFie ld: boolea n;
  1691   begin
  1692     Result : = (StrToIn tDef(FID,0 ) <= 0);
  1693   end;
  1694  
  1695   procedure  TTemplateF ield.SetSe pLines(con st Value:  boolean);
  1696   begin
  1697     if(FSepL ines <> Va lue) and C anModify t hen
  1698       FSepLi nes := Val ue
  1699   end;
  1700  
  1701   procedure  TTemplateF ield.SetIn crement(co nst Value:  integer);
  1702   begin
  1703     if(FIncr ement <> V alue) and  CanModify  then
  1704       FIncre ment := Va lue;
  1705   end;
  1706  
  1707   procedure  TTemplateF ield.SetIn dent(const  Value: in teger);
  1708   begin
  1709     if(FInde nt <> Valu e) and Can Modify the n
  1710       FInden t := Value ;
  1711   end;
  1712  
  1713   procedure  TTemplateF ield.SetMa xVal(const  Value: in teger);
  1714   begin
  1715     if(FMaxV al <> Valu e) and Can Modify the n
  1716       FMaxVa l := Value ;
  1717   end;
  1718  
  1719   procedure  TTemplateF ield.SetMi nVal(const  Value: in teger);
  1720   begin
  1721     if(FMinV al <> Valu e) and Can Modify the n
  1722       FMinVa l := Value ;
  1723   end;
  1724  
  1725   procedure  TTemplateF ield.SetPa d(const Va lue: integ er);
  1726   begin
  1727     if(FPad  <> Value)  and CanMod ify then
  1728       FPad : = Value;
  1729   end;
  1730  
  1731   procedure  TTemplateF ield.SetTe xtLen(cons t Value: i nteger);
  1732   begin
  1733     if(FText Len <> Val ue) and Ca nModify th en
  1734       FTextL en := Valu e;
  1735   end;
  1736  
  1737   procedure  TTemplateF ield.SetUR L(const Va lue: strin g);
  1738   begin
  1739     if(FURL  <> Value)  and CanMod ify then
  1740       FURL : = Value;
  1741   end;
  1742  
  1743   function T TemplateFi eld.GetReq uired: boo lean;
  1744   begin
  1745     if FFldT ype in NoR equired th en
  1746       Result  := FALSE
  1747     else
  1748       Result  := FRequi red;
  1749   end;
  1750  
  1751   procedure  TTemplateF ield.SetDa teType(con st Value:  TTmplFldDa teType);
  1752   begin
  1753     if(FDate Type <> Va lue) and C anModify t hen
  1754       FDateT ype := Val ue;
  1755   end;
  1756  
  1757   { TTemplat eDialogEnt ry }
  1758   const
  1759     EOL_MARK ER = #182;
  1760     SR_BREAK    = #186;
  1761  
  1762   procedure  PanelDestr oy(AData:  Pointer; S ender: TOb ject);
  1763   var
  1764     idx: int eger;
  1765     dlg: TTe mplateDial ogEntry;
  1766  
  1767   begin
  1768     dlg := T TemplateDi alogEntry( AData);
  1769     idx := u Entries.In dexOf(dlg. FID);
  1770     if(idx > = 0) then
  1771       uEntri es.Delete( idx);
  1772     dlg.FPan elDying :=  TRUE;
  1773     dlg.Free ;
  1774   end;
  1775  
  1776   constructo r TTemplat eDialogEnt ry.Create( AParent: T WinControl ; AID, Tex t: string) ;
  1777   var
  1778     CtrlID,  idx, i, j,  flen: int eger;
  1779     txt, Fld Name: stri ng;
  1780     Fld: TTe mplateFiel d;
  1781  
  1782   begin
  1783     FID := A ID;
  1784     FText :=  Text;
  1785     FControl s := TStri ngList.Cre ate;
  1786     FIndents  := TStrin gList.Crea te;
  1787     FFont :=  TFont.Cre ate;
  1788     FFont.As sign(TOREx posedContr ol(AParent ).Font);
  1789     FControl s.Text :=  Text;
  1790     if(FCont rols.Count  > 1) then
  1791     begin
  1792       for i  := 1 to FC ontrols.Co unt-1 do
  1793         FCon trols[i] : = EOL_MARK ER + FCont rols[i];
  1794       if not  ScreenRea derSystemA ctive then
  1795         Stri pScreenRea derCodes(F Controls);
  1796     end;
  1797     FFirstBu ild := TRU E;
  1798     FPanel : = TDlgFiel dPanel.Cre ate(AParen t.Owner);
  1799     FPanel.P arent := A Parent;
  1800     FPanel.B evelOuter  := bvNone;
  1801     FPanel.C aption :=  '';
  1802     FPanel.F ont.Assign (FFont);
  1803     UpdateCo lorsFor508 Compliance (FPanel, T RUE);
  1804     idx := 0 ;
  1805     while (i dx < FCont rols.Count ) do
  1806     begin
  1807       txt :=  FControls [idx];
  1808       i := p os(Templat eFieldBegi nSignature , txt);
  1809       if(i >  0) then
  1810       begin
  1811         if(c opy(txt, i  + Templat eFieldSign atureLen,  1) = Field IDDelim) t hen
  1812         begi n
  1813           Ct rlID := St rToIntDef( copy(txt,  i + Templa teFieldSig natureLen  + 1, Field IDLen-1),  0);
  1814           de lete(txt,i  + Templat eFieldSign atureLen,  FieldIDLen );
  1815         end
  1816         else
  1817           Ct rlID := 0;
  1818         j :=  pos(Templ ateFieldEn dSignature , copy(txt , i + Temp lateFieldS ignatureLe n, MaxInt) );
  1819         if(j  > 0) then
  1820         begi n
  1821           in c(j, i + T emplateFie ldSignatur eLen - 1);
  1822           fl en := j -  i - Templa teFieldSig natureLen;
  1823           Fl dName := c opy(txt, i  + Templat eFieldSign atureLen,  flen);
  1824           Fl d := GetTe mplateFiel d(FldName,  FALSE);
  1825           de lete(txt,i ,flen + Te mplateFiel dSignature Len + 1);
  1826           if (assigned( Fld)) then
  1827           be gin
  1828              FControls[ idx] := co py(txt,1,i -1);
  1829              if(Fld.Req uired) the n
  1830              begin
  1831                if Scree nReaderSys temActive  then
  1832                begin
  1833                  if Fld .FFldType  in [dftChe ckBoxes, d ftRadioBut tons] then
  1834                    FCon trols[idx]  := FContr ols[idx] +  ScreenRea derStopCod e;
  1835                end;
  1836                FControl s[idx] :=  FControls[ idx] + '*' ;
  1837              end;
  1838              Fld.Create DialogCont rols(Self,  idx, Ctrl ID);  // C reates con trols
  1839              FControls. Insert(idx +1,copy(tx t,i,MaxInt ));
  1840           en d
  1841           el se
  1842           be gin
  1843              FControls[ idx] := tx t;
  1844              dec(idx);
  1845           en d;
  1846         end
  1847         else
  1848         begi n
  1849           de lete(txt,i ,TemplateF ieldSignat ureLen);
  1850           FC ontrols[id x] := txt;
  1851           de c(idx);
  1852         end;
  1853       end;
  1854       inc(id x);
  1855     end;
  1856     if Scree nReaderSys temActive  then
  1857     begin
  1858       idx :=  0;
  1859       while  (idx < FCo ntrols.Cou nt) do
  1860       begin
  1861         txt  := FContro ls[idx];
  1862         i :=  pos(Scree nReaderSto pCode, txt );
  1863         if i  > 0 then
  1864         begi n
  1865           FC ontrols[id x] := copy (txt, 1, i -1);
  1866           tx t := copy( txt, i + S creenReade rStopCodeL en, MaxInt );
  1867           FC ontrols.In sert(idx+1 , SR_BREAK  + txt);
  1868         end;
  1869         inc( idx);
  1870       end;
  1871     end;
  1872   end;
  1873  
  1874   destructor  TTemplate DialogEntr y.Destroy;
  1875   begin
  1876     if assig ned(FOnDes troy) then
  1877       FOnDes troy(Self) ;
  1878     KillLabe ls;
  1879     KillObj( @FControls , TRUE);
  1880     if FPane lDying the n
  1881       FPanel  := nil
  1882     else
  1883       FreeAn dNil(FPane l);
  1884     FreeAndN il(FFont);
  1885     FreeAndN il(FIndent s);
  1886     inherite d;
  1887   end;
  1888  
  1889   procedure  TTemplateD ialogEntry .DoChange( Sender: TO bject);
  1890   begin
  1891     if (not  FUpdating)  and assig ned(FOnCha nge) then
  1892       FOnCha nge(Self);
  1893   end;
  1894  
  1895   function T TemplateDi alogEntry. GetControl Text(CtrlI D: integer ; NoCommas : boolean;  var Found Entry: boo lean; Auto Wrap: bool ean; emFie ld: string  = ''; Crn tLnTxt: St ring = '';  AutoWrapI ndent: int eger = 0;  NoFormat:  boolean =  false): st ring;
  1896   var
  1897     x, i, j,  ind, idx:  integer;
  1898     ctrl: TC ontrol;
  1899     Done: bo olean;
  1900     iString:  string;
  1901     iField:  TTemplateF ield;
  1902     iTemp: T StringList ;
  1903     TmpChar:  integer;
  1904     TmpStrin g, aStr: S tring;
  1905     TmpEvt:  TNotifyEve nt;
  1906     TmpSelSt art: Integ er;
  1907  
  1908     function  GetOrigin alItem(ist r: string) : string;
  1909     begin
  1910       Result  := '';
  1911       if emF ield <> ''  then
  1912       begin
  1913         iFie ld := GetT emplateFie ld(emField , false);
  1914         iTem p := nil;
  1915         if i Field <> n il then
  1916           tr y
  1917              iTemp := T StringList .Create;
  1918              iTemp.Text  := StripE mbedded(iF ield.Items );
  1919              x := iTemp .IndexOf(i str);
  1920              if x >= 0  then
  1921              begin
  1922                iTemp.Te xt := iFie ld.Items;
  1923                Result : = iTemp.St rings[x];
  1924              end;
  1925           fi nally
  1926              iTemp.Free ;
  1927           en d;
  1928       end;
  1929     end;
  1930  
  1931   begin
  1932     Result : = '';
  1933     Done :=  false;
  1934     ind := - 1;
  1935     TmpEvt : = nil;
  1936     for i :=  0 to FCon trols.Coun t - 1 do
  1937     begin
  1938       ctrl : = TControl (FControls .Objects[i ]);
  1939       if (as signed(ctr l)) and (c trl.Tag =  CtrlID) th en
  1940       begin
  1941         Foun dEntry :=  TRUE;
  1942         Done  := TRUE;
  1943         if i nd < 0 the n
  1944         begi n
  1945           id x := FInde nts.IndexO fObject(ct rl);
  1946           if  idx >= 0  then
  1947              ind := Str ToIntDef(P iece(FInde nts[idx],  U, 2), 0)
  1948           el se
  1949              ind := 0;
  1950         end;
  1951         if ( ctrl is TC PRSTemplat eFieldLabe l) then
  1952         begi n
  1953           if  not TCPRS TemplateFi eldLabel(c trl).Exclu de then
  1954           be gin
  1955              if emField  <> '' the n
  1956              begin
  1957                iField : = GetTempl ateField(e mField, fa lse);
  1958                case iFi eld.FldTyp e of
  1959                  dftHyp erlink:
  1960                    if i Field.Edit Default <>  '' then
  1961                      Re sult := iF ield.EditD efault
  1962                    else
  1963                      Re sult := iF ield.URL;
  1964                  dftTex t:
  1965                    begi n
  1966                      iS tring := i Field.Item s;
  1967                      if  copy(iStr ing, Lengt h(iString)  - 1, 2) =  CRLF then
  1968                         Delete(iSt ring, Leng th(iString ) - 1, 2);
  1969                      Re sult := iS tring;
  1970                    end;
  1971                else { c ase }
  1972                  Result  := TCPRST emplateFie ldLabel(ct rl).Captio n
  1973                end; { c ase iField .FldType }
  1974              end { if e mField }
  1975              else
  1976                Result : = TCPRSTem plateField Label(ctrl ).Caption;
  1977           en d;
  1978         end
  1979         else
  1980             // !!!!!!  CODE ADDED  BACK IN -   DN S      BELLC !!!! !!
  1981           if  (ctrl is  TEdit) the n
  1982              Result :=  TEdit(ctrl ).Text
  1983           el se if (ctr l is TORCo mboBox) th en
  1984           be gin
  1985              Result :=  TORComboBo x(ctrl).Te xt;
  1986              iString :=  GetOrigin alItem(Res ult);
  1987              if iString  <> '' the n
  1988                Result : = iString;
  1989           en d
  1990           el se if (ctr l is TORDa teCombo) t hen
  1991              Result :=  TORDateCom bo(ctrl).T ext + ':'  + FloatToS tr(TORDate Combo(ctrl ).FMDate)
  1992           el se
  1993               { !!!!!! T HIS HAS BE EN REMOVED  AS IT CAU SED PROBLE MS WITH RE MINDER DIA LOGS -  DN S      BELLC !!!! !!
  1994                if(Ctrl  is TORDate Box) then  begin
  1995                if TORDa teBox(Ctrl ).IsValid  then
  1996                Result : = TORDateB ox(Ctrl).T ext
  1997                else
  1998                Result : = '';
  1999                end else
  2000              }
  2001               // !!!!!!  CODE ADDED  BACK IN -   DN S      BELLC !!!! !!
  2002              if (ctrl i s TORDateB ox) then
  2003                Result : = TORDateB ox(ctrl).T ext
  2004              else if (c trl is TRi chEdit) th en
  2005              begin
  2006                // If we  do not ne ed to form at this (R eminder va lues) or t here is no  indent an d not auto wrap
  2007                if ((ind  = 0) and  (not AutoW rap)) or N oFormat th en
  2008                  //Resu lt := TRic hEdit(ctrl ).Lines.Te xt
  2009                  Result  := TRichE dit(ctrl). Text
  2010                else
  2011                begin
  2012                  { for  j := 0 to  TRichEdit( Ctrl).Line s.Count-1  do
  2013                    begi n
  2014                    if A utoWrap th en
  2015                    begi n
  2016                    if(R esult <> ' ') then
  2017                    Resu lt := Resu lt + ' ';
  2018                    Resu lt := Resu lt + TRich Edit(Ctrl) .Lines[j];
  2019                    end
  2020                    else
  2021                    begi n
  2022                    if(R esult <> ' ') then
  2023                    Resu lt := Resu lt + CRLF;
  2024                    Resu lt := Resu lt + Strin gOfChar('  ', ind) +  TRichEdit( Ctrl).Line s[j];
  2025                    end;
  2026                    end;  }
  2027                  // If  the object  shares a  line with  text than  take this  into accou nt
  2028                  If Len gth(CrntLn Txt) > 0 t hen
  2029                  begin
  2030                    // S ave the pr evious ver sion of th e text
  2031                    TmpS tring := T RichEdit(c trl).Text;
  2032                    // W e nee di d isable the  onchange  event temp orarily (R eminders)
  2033                    TmpE vt := nil;
  2034                    TmpE vt := TRic hEdit(ctrl ).OnChange ;
  2035                    TRic hEdit(ctrl ).OnChange  := nil;
  2036                    TmpS elStart :=  TRichEdit (ctrl).Sel Start;
  2037                    // A dd the hea der to our  text but  remove the  indent le ngth (as l ong as no  text)
  2038                    J :=  ind + 1;
  2039                    aStr  := CrntLn Txt + TRic hEdit(ctrl ).Text;
  2040  
  2041                    if J  > Length( aStr) then
  2042                     J : = Length(a Str);
  2043  
  2044                    whil e (J > 0)  and (aStr[ J] <> ' ')  do
  2045                    begi n
  2046                      De c(J);
  2047                    end;
  2048  
  2049                    TRic hEdit(ctrl ).Text :=  copy(aStr,  J, Length (aStr));
  2050  
  2051                  end;
  2052                  // If  we are add ing CTLF a nd we exce ed MAX_WRA P_WIDTH ch aracters
  2053                  if (no t AutoWrap ) and ((in d + Length (TRichEdit (ctrl).Lin es[0])) >  MAX_WRAP_W IDTH) then
  2054                  begin
  2055                    // I f we are s haring a l ine, do no t add lead ing indent
  2056                    if L ength(Crnt LnTxt) > 0  then
  2057                      Re sult := St ringReplac e(WrapText (StringRep lace(TRich Edit(ctrl) .Text, ''' ', '''''',  [rfReplac eAll, rfIg noreCase]) , CRLF + S tringOfCha r(' ', ind ), [' '],  (MAX_WRAP_ WIDTH - in d)), ''''' ', '''', [ rfReplaceA ll, rfIgno reCase])
  2058                    else
  2059                      Re sult := St ringOfChar (' ', ind)  + StringR eplace(Wra pText(Stri ngReplace( TRichEdit( ctrl).Text , '''', '' '''', [rfR eplaceAll,  rfIgnoreC ase]), CRL F + String OfChar(' ' , ind), ['  '], (MAX_ WRAP_WIDTH  - ind)),  '''''', '' '', [rfRep laceAll, r fIgnoreCas e]);
  2060                  end
  2061                  else
  2062                  begin
  2063                    // I f this is  autowrap t hen wrap w ith END OF  LINE ASCI I char
  2064                    if A utoWrap th en
  2065                      Re sult := St ringReplac e(WrapText (StringRep lace(TRich Edit(ctrl) .Text, ''' ', '''''',  [rfReplac eAll, rfIg noreCase]) , #3 + Str ingOfChar( ' ', ind),  [' '], (A utoWrapInd ent - ind) ), '''''',  '''', [rf ReplaceAll , rfIgnore Case])
  2066                    else
  2067                    begi n
  2068                      //  we can fi t our text  within MA X_WRAP_WID TH.
  2069                      fo r j := 0 t o TRichEdi t(ctrl).Li nes.Count  - 1 do
  2070                      be gin
  2071                         if (Result  <> '') th en
  2072                           Result : = Result +  CRLF + St ringOfChar (' ', ind) ;
  2073                         if (Length (CrntLnTxt ) = 0) and  (Result =  '') then
  2074                           Result : = StringOf Char(' ',  ind) + TRi chEdit(ctr l).Lines[j ]
  2075                         else
  2076                           Result : = Result +  TRichEdit (ctrl).Lin es[j];
  2077                      en d;
  2078                    end;
  2079                  end;
  2080                  // If  we are sha ring a lin e then we  need to re move its t ext from t he
  2081                  if Len gth(CrntLn Txt) > 0 t hen
  2082                  begin
  2083                    for  TmpChar :=  0 to ((Le ngth(CrntL nTxt) - in d) - 1) do
  2084                    begi n
  2085                      De lete(Resul t, 1, 1);
  2086                    end;
  2087                    // R eset text  and change  event
  2088                  //  Tm pSelStart  := TRichEd it(ctrl).S elStart;
  2089                    TRic hEdit(ctrl ).Text :=  TmpString;
  2090                    if T RichEdit(c trl).SelSt art <> Tmp SelStart t hen
  2091                      TR ichEdit(ct rl).SelSta rt := TmpS elStart;
  2092                    TRic hEdit(ctrl ).OnChange  := TmpEvt ;
  2093                    TmpE vt := nil;
  2094                  end;
  2095                  ind :=  0;
  2096                end;
  2097              end
  2098              else
  2099                  { !!!!!! T HIS HAS BE EN REMOVED  AS IT CAU SED PROBLE MS WITH RE MINDER DIA LOGS -  DN S      BELLC !!!! !!
  2100                  if(Ctr l is TEdit ) then
  2101                  Result  := TEdit( Ctrl).Text
  2102                  else }
  2103                if (ctrl  is TORChe ckBox) the n
  2104                begin
  2105                  Done : = false;
  2106                  if (TO RCheckBox( ctrl).Chec ked) then
  2107                  begin
  2108                    if ( Result <>  '') then
  2109                    begi n
  2110                      if  NoCommas  then
  2111                         Result :=  Result + ' |'
  2112                      el se
  2113                         Result :=  Result + ' , ';
  2114                    end;
  2115                    iStr ing := Get OriginalIt em(TORChec kBox(ctrl) .Caption);
  2116                    if i String <>  '' then
  2117                      Re sult := Re sult + iSt ring
  2118                    else
  2119                      Re sult := Re sult + TOR CheckBox(c trl).Capti on;
  2120                  end;
  2121                end
  2122                else if  (ctrl is T fraTemplat eFieldButt on) then
  2123                begin
  2124                  Result  := TfraTe mplateFiel dButton(ct rl).Button Text;
  2125                  iStrin g := GetOr iginalItem (Result);
  2126                  if iSt ring <> ''  then
  2127                    Resu lt := iStr ing;
  2128                end
  2129                else if  (ctrl is T Panel) the n
  2130                begin
  2131                  for j  := 0 to ct rl.Compone ntCount -  1 do
  2132                    if c trl.Compon ents[j] is  TUpDown t hen
  2133                    begi n
  2134                      Re sult := In tToStr(TUp Down(ctrl. Components [j]).Posit ion);
  2135                      br eak;
  2136                    end;
  2137                end;
  2138       end;
  2139       if Don e then
  2140         brea k;
  2141     end;
  2142     if (ind  > 0) and ( not NoComm as) then
  2143       Result  := String OfChar(' ' , ind) + R esult;
  2144   end;
  2145  
  2146   function T TemplateDi alogEntry. GetFieldVa lues: stri ng;
  2147   var
  2148     i: integ er;
  2149     Ctrl: TC ontrol;
  2150     CtrlID:  integer;
  2151     TmpIDs:  TList;
  2152     TmpSL: T StringList ;
  2153     Dummy: b oolean;
  2154  
  2155   begin
  2156     Result : = '';
  2157     TmpIDs : = TList.Cr eate;
  2158     try
  2159       TmpSL  := TString List.Creat e;
  2160       try
  2161         for  i := 0 to  FControls. Count-1 do
  2162         begi n
  2163           Ct rl := TCon trol(FCont rols.Objec ts[i]);
  2164           if (assigned( Ctrl)) the n
  2165           be gin
  2166              CtrlID :=  Ctrl.Tag;
  2167              if(TmpIDs. IndexOf(Po inter(Ctrl ID)) < 0)  then
  2168              begin
  2169                TmpSL.Ad d(IntToStr (CtrlID) +  U + Strin gReplace(G etControlT ext(CtrlID ,TRUE, Dum my, FALSE,  '','',0,t rue), CRLF , '',[rfRe placeAll,  rfIgnoreCa se]));
  2170                TmpIDs.A dd(Pointer (CtrlID));
  2171              end;
  2172           en d;
  2173         end;
  2174         Resu lt := TmpS L.CommaTex t;
  2175       finall y
  2176         TmpS L.Free;
  2177       end;
  2178     finally
  2179       TmpIDs .Free;
  2180     end;
  2181   end;
  2182  
  2183   function T TemplateDi alogEntry. GetPanel(M axLen: int eger; APar ent: TWinC ontrol;
  2184                                             O wningCheck Box: TCPRS DialogPare ntCheckBox ): TDlgFie ldPanel;
  2185   var
  2186     i, x, y,  cnt, idx,  ind, yinc , ybase, M axX: integ er;
  2187     MaxTextL en: intege r;  {Max n um of char s per line  in pixels }
  2188     MaxChars : integer;     {Max n um of char s per line }
  2189     txt: str ing;
  2190     ctrl: TC ontrol;
  2191     LastLine Blank: boo lean;
  2192     sLbl: TC PRSDialogS taticLabel ;
  2193     nLbl: TV A508Chaine dLabel;
  2194     sLblHeig ht: intege r;
  2195     TabOrdr:  integer;
  2196   const
  2197     FOCUS_RE CT_MARGIN  = 2; {The  margin aro und the pa nel so the  label won 't
  2198                             overla y the focu s rect on  its parent  panel.}
  2199  
  2200     procedur e Add2TabO rder(ctrl:  TWinContr ol);
  2201     begin
  2202       ctrl.T abOrder :=  TabOrdr;
  2203       inc(Ta bOrdr);
  2204     end;
  2205  
  2206     function  StripSRCo de(var txt : string;  code: stri ng; len: i nteger): i nteger;
  2207     begin
  2208       Result  := pos(co de, txt);
  2209       if Res ult > 0 th en
  2210       begin
  2211         dele te(txt,Res ult,len);
  2212         dec( Result);
  2213       end
  2214       else
  2215         Resu lt := -1;
  2216     end;
  2217  
  2218     procedur e DoLabel( Atxt: stri ng);
  2219     var
  2220       ctrl:  TControl;
  2221       tempLb l: TVA508C hainedLabe l;
  2222  
  2223     begin
  2224       if Scr eenReaderS ystemActiv e then
  2225       begin
  2226         if a ssigned(sL bl) then
  2227         begi n
  2228           te mpLbl := T VA508Chain edLabel.Cr eate(nil);
  2229           if  assigned( nLbl) then
  2230              nLbl.NextL abel := te mpLbl
  2231           el se
  2232              sLbl.NextL abel := te mpLbl;
  2233           nL bl := temp Lbl;
  2234           ct rl := nLbl ;
  2235         end
  2236         else
  2237         begi n
  2238           sL bl := TCPR SDialogSta ticLabel.C reate(nil) ;
  2239           ct rl := sLbl ;
  2240         end;
  2241       end
  2242       else
  2243         ctrl  := TLabel .Create(ni l);
  2244       SetOrd Prop(ctrl,  ShowAccel CharProper ty, ord(FA LSE));
  2245       SetStr Prop(ctrl,  CaptionPr operty, At xt);
  2246       ctrl.P arent := F Panel;
  2247       ctrl.L eft := x;
  2248       ctrl.T op := y;
  2249       if ctr l = sLbl t hen
  2250       begin
  2251         Add2 TabOrder(s Lbl);
  2252         sLbl .Height :=  sLblHeigh t;
  2253         Scre enReaderSy stem_Curre ntLabel(sL bl);
  2254       end;
  2255       if Scr eenReaderS ystemActiv e then
  2256         Scre enReaderSy stem_AddTe xt(Atxt);
  2257       Update ColorsFor5 08Complian ce(ctrl);
  2258       inc(x,  ctrl.Widt h);
  2259     end;
  2260  
  2261     procedur e Init;
  2262     var
  2263       lbl :  TLabel;
  2264     begin
  2265       if(FFi rstBuild)  then
  2266         FFir stBuild :=  FALSE
  2267       else
  2268         Kill Labels;
  2269       y := F OCUS_RECT_ MARGIN; {p lacement o f labels o n panel so  they don' t cover th e}
  2270       x := F OCUS_RECT_ MARGIN; {f ocus recta ngle}
  2271       MaxX : = 0;
  2272       //ybas e := FontH eightPixel (FFont.Han dle) + 1 +  (FOCUS_RE CT_MARGIN  * 2);  AGP  commentou t line for
  2273                                                                                     //rem inder spac ing
  2274       ybase  := FontHei ghtPixel(F Font.Handl e) + 2;
  2275       yinc : = ybase;
  2276       LastLi neBlank :=  FALSE;
  2277       sLbl : = nil;
  2278       nLbl : = nil;
  2279       TabOrd r := 0;
  2280       if Scr eenReaderS ystemActiv e then
  2281       begin
  2282         Scre enReaderSy stem_Curre ntCheckBox (OwningChe ckBox);
  2283         lbl  := TLabel. Create(nil );
  2284         try
  2285           lb l.Parent : = FPanel;
  2286           sL blHeight : = lbl.Heig ht + 2;
  2287         fina lly
  2288           lb l.Free;
  2289         end;
  2290  
  2291       end;
  2292     end;
  2293  
  2294     procedur e Text508W ork;
  2295     var
  2296       Contin ueCode: bo olean;
  2297     begin
  2298       if Str ipCode(txt , SR_BREAK ) then
  2299       begin
  2300         Scre enReaderSy stem_Stop;
  2301         nLbl  := nil;
  2302         sLbl  := nil;
  2303       end;
  2304  
  2305       Contin ueCode :=  FALSE;
  2306       while  StripSRCod e(txt, Scr eenReaderC ontinueCod e, ScreenR eaderConti nueCodeLen ) >= 0 do
  2307         Cont inueCode : = TRUE;
  2308       while  StripSRCod e(txt, Scr eenReaderC ontinueCod eOld, Scre enReaderCo ntinueCode OldLen) >=  0 do
  2309         Cont inueCode : = TRUE;
  2310       if Con tinueCode  then
  2311         Scre enReaderSy stem_Conti nue;
  2312     end;
  2313  
  2314     procedur e Ctrl508W ork(ctrl:  TControl);
  2315     var
  2316       lbl: T CPRSTempla teFieldLab el;
  2317     begin
  2318       if (Ct rl is TCPR STemplateF ieldLabel)  and (not  (Ctrl is T CPRSDialog HyperlinkL abel)) the n
  2319       begin
  2320         lbl  := Ctrl as  TCPRSTemp lateFieldL abel;
  2321         if t rim(lbl.Ca ption) <>  '' then
  2322         begi n
  2323           Sc reenReader System_Cur rentLabel( lbl);
  2324           Sc reenReader System_Add Text(lbl.C aption);
  2325         end
  2326         else
  2327         begi n
  2328           lb l.TabStop  := FALSE;
  2329           Sc reenReader System_Sto p;
  2330         end;
  2331         Add2 TabOrder(T WinControl (ctrl));
  2332       end
  2333       else
  2334       begin
  2335         if c trl is TWi nControl t hen
  2336           Ad d2TabOrder (TWinContr ol(ctrl));
  2337         if S upports(ct rl, ICPRSD ialogCompo nent) then
  2338           Sc reenReader System_Cur rentCompon ent(ctrl a s ICPRSDia logCompone nt);
  2339       end;
  2340       sLbl : = nil;
  2341       nLbl : = nil;
  2342     end;
  2343  
  2344     procedur e NextLine ;
  2345     begin
  2346       if(Max X < x) the n
  2347         MaxX  := x;
  2348       x := F OCUS_RECT_ MARGIN;  { leave two  pixels on  the left f or the Foc us Rect}
  2349       inc(y,  yinc);
  2350       yinc : = ybase;
  2351     end;
  2352  
  2353   begin
  2354     MaxTextL en := MaxL en - (FOCU S_RECT_MAR GIN * 2);{ save room  for the fo cus rectan gle on the  panel}
  2355     if(FFirs tBuild or  (FPanel.Wi dth <> Max Len)) then
  2356     begin
  2357       Init;
  2358       for i  := 0 to FC ontrols.Co unt-1 do
  2359       begin
  2360         txt  := FContro ls[i];
  2361         if S creenReade rSystemAct ive then
  2362           Te xt508Work;
  2363         if S tripCode(t xt,EOL_MAR KER) then
  2364         begi n
  2365           if ((x <> 0)  or LastLin eBlank) th en
  2366              NextLine;
  2367           La stLineBlan k := (txt  = '');
  2368         end;
  2369         if(t xt <> '')  then
  2370         begi n
  2371           wh ile(txt <>  '') do
  2372           be gin
  2373              cnt := Num CharsFitIn Width(FFon t.Handle,  txt, MaxTe xtLen-x);
  2374              MaxChars : = cnt;
  2375              if(cnt >=  length(txt )) then
  2376              begin
  2377                DoLabel( txt);
  2378                txt := ' ';
  2379              end
  2380              else
  2381              if(cnt < 1 ) then
  2382                NextLine
  2383              else
  2384              begin
  2385                repeat
  2386                  if(txt [cnt+1] =  ' ') then
  2387                  begin
  2388                    DoLa bel(copy(t xt,1,cnt)) ;
  2389                    Next Line;
  2390                    txt  := copy(tx t, cnt + 1 , MaxInt);
  2391                    brea k;
  2392                  end
  2393                  else
  2394                    dec( cnt);
  2395                until(cn t = 0);
  2396                if(cnt =  0) then
  2397                begin
  2398                  if(x =  FOCUS_REC T_MARGIN)  then {If x  is at the  far left  margin...}
  2399                  begin
  2400                    DoLa bel(Copy(t xt,1,MaxCh ars));
  2401                    Next Line;
  2402                    txt  := copy(tx t, MaxChar s + 1, Max Int);
  2403                  end
  2404                  else
  2405                    Next Line;
  2406                end;
  2407              end;
  2408           en d;
  2409         end
  2410         else
  2411         begi n
  2412           ct rl := TCon trol(FCont rols.Objec ts[i]);
  2413           if (assigned( ctrl)) the n
  2414           be gin
  2415              if ScreenR eaderSyste mActive th en
  2416                Ctrl508W ork(ctrl);
  2417              idx := FIn dents.Inde xOfObject( Ctrl);
  2418              if idx >=  0 then
  2419                ind := S trToIntDef (Piece(FIn dents[idx] , U, 1), 0 )
  2420              else
  2421                ind := 0 ;
  2422              if(x > 0)  then
  2423              begin
  2424                if (x <  MaxLen) an d (Ctrl is  TORCheckB ox) and (T ORCheckBox (Ctrl).Str ingData =  NewLine) t hen
  2425                  x := M axLen;
  2426                if((ctrl .Width + x  + ind) >  MaxLen) th en
  2427                  NextLi ne;
  2428              end;
  2429              inc(x,ind) ;
  2430              Ctrl.Left  := x;
  2431              Ctrl.Top : = y;
  2432              inc(x, Ctr l.Width +  4);
  2433              if yinc <=  Ctrl.Heig ht then
  2434                yinc :=  Ctrl.Heigh t + 2;
  2435              if (x < Ma xLen) and  ((Ctrl is  TRichEdit)  or
  2436                 ((Ctrl  is TLabel)  and (pos( CRLF, TLab el(Ctrl).C aption) >  0))) then
  2437                x := Max Len;
  2438           en d;
  2439         end;
  2440       end;
  2441       NextLi ne;
  2442       FPanel .Height :=  (y-1) + ( FOCUS_RECT _MARGIN *  2); //AGP  added Focu s_rect_mar gin for Re minder spa cing
  2443       FPanel .Width :=  MaxX + FOC US_RECT_MA RGIN;
  2444     end;
  2445     if(FFiel dValues <>  '') then
  2446       SetFie ldValues(F FieldValue s);
  2447     if Scree nReaderSys temActive  then
  2448       Screen ReaderSyst em_Stop;
  2449     Result : = FPanel;
  2450   end;
  2451  
  2452   function T TemplateDi alogEntry. GetText: s tring;
  2453   begin
  2454     Result : = ResolveT emplateFie lds(FText,  FALSE);
  2455   end;
  2456  
  2457   procedure  TTemplateD ialogEntry .KillLabel s;
  2458   var
  2459     i, idx:  integer;
  2460     obj: TOb ject;
  2461     max: int eger;
  2462  
  2463   begin
  2464     if(assig ned(FPanel )) then
  2465     begin
  2466       max :=  FPanel.Co ntrolCount -1;
  2467       for i  := max dow nto 0 do
  2468       begin
  2469   // deletin g TVA508St aticText c an delete  several TV A508Chaine dLabel com ponents
  2470         if i  < FPanel. ControlCou nt then
  2471         begi n
  2472           ob j := FPane l.Controls [i];
  2473           if  (not (obj  is TVA508 ChainedLab el)) and
  2474               ((obj is  TLabel) or  (obj is T VA508Stati cText)) th en
  2475           be gin
  2476              idx := FCo ntrols.Ind exOfObject (obj);
  2477              if idx < 0  then
  2478                obj.Free ;
  2479           en d;
  2480         end;
  2481       end;
  2482     end;
  2483   end;
  2484  
  2485   procedure  TTemplateD ialogEntry .SetAutoDe stroyOnPan elFree(
  2486     const Va lue: boole an);
  2487   var
  2488     M: TMeth od;
  2489  
  2490   begin
  2491     FAutoDes troyOnPane lFree := V alue;
  2492     if(Value ) then
  2493     begin
  2494       M.Data  := Self;
  2495       M.Code  := @Panel Destroy;
  2496       FPanel .OnDestroy  := TNotif yEvent(M);
  2497     end
  2498     else
  2499       FPanel .OnDestroy  := nil;
  2500   end;
  2501  
  2502   procedure  TTemplateD ialogEntry .SetContro lText(Ctrl ID: intege r; AText:  string);
  2503   var
  2504     cnt, i,  j: integer ;
  2505     Ctrl: TC ontrol;
  2506     Done: bo olean;
  2507  
  2508   begin
  2509     FUpdatin g := TRUE;
  2510     try
  2511       Done : = FALSE;
  2512       cnt :=  0;
  2513       for i  := 0 to FC ontrols.Co unt-1 do
  2514       begin
  2515         Ctrl  := TContr ol(FContro ls.Objects [i]);
  2516         if(a ssigned(Ct rl)) and ( Ctrl.Tag =  CtrlID) t hen
  2517         begi n
  2518           Do ne := TRUE ;
  2519           if (Ctrl is T Label) the n
  2520              TLabel(Ctr l).Caption  := AText
  2521           el se
  2522           if (Ctrl is T Edit) then
  2523              TEdit(Ctrl ).Text :=  AText
  2524           el se
  2525           if (Ctrl is T ORComboBox ) then
  2526              TORComboBo x(Ctrl).Se lectByID(A Text)
  2527           el se
  2528           if (Ctrl is T RichEdit)  then
  2529              TRichEdit( Ctrl).Line s.Text :=  AText
  2530           el se
  2531           if (Ctrl is T ORDateComb o) then
  2532              TORDateCom bo(Ctrl).F MDate := M akeFMDateT ime(piece( AText,':', 2))
  2533           el se
  2534           if (Ctrl is T ORDateBox)  then
  2535              TORDateBox (Ctrl).Tex t := AText
  2536           el se
  2537           if (Ctrl is T ORCheckBox ) then
  2538           be gin
  2539              Done := FA LSE;
  2540              TORCheckBo x(Ctrl).Ch ecked := F ALSE;         //<-PSI -06-170-AD DED THIS L INE - v27. 23 - RV
  2541              if(cnt = 0 ) then
  2542                cnt := D elimCount( AText, '|' ) + 1;
  2543              for j := 1  to cnt do
  2544              begin
  2545                if(TORCh eckBox(Ctr l).Caption  = piece(A Text,'|',j )) then
  2546                  TORChe ckBox(Ctrl ).Checked  := TRUE;
  2547              end;
  2548           en d
  2549           el se
  2550           if (Ctrl is T fraTemplat eFieldButt on) then
  2551              TfraTempla teFieldBut ton(Ctrl). ButtonText  := AText
  2552           el se
  2553           if (Ctrl is T Panel) the n
  2554           be gin
  2555              for j := 0  to Ctrl.C omponentCo unt-1 do
  2556                if Ctrl. Components [j] is TUp Down then
  2557                begin
  2558                  TUpDow n(Ctrl.Com ponents[j] ).Position  := StrToI ntDef(ATex t,0);
  2559                  break;
  2560                end;
  2561           en d;
  2562         end;
  2563         if D one then b reak;
  2564       end;
  2565     finally
  2566       FUpdat ing := FAL SE;
  2567     end;
  2568   end;
  2569  
  2570   procedure  TTemplateD ialogEntry .SetFieldV alues(cons t Value: s tring);
  2571   var
  2572     i: integ er;
  2573     TmpSL: T StringList ;
  2574  
  2575   begin
  2576     FFieldVa lues := Va lue;
  2577     TmpSL :=  TStringLi st.Create;
  2578     try
  2579       TmpSL. CommaText  := Value;
  2580       for i  := 0 to Tm pSL.Count- 1 do
  2581         SetC ontrolText (StrToIntD ef(Piece(T mpSL[i], U , 1), 0),  Piece(TmpS L[i], U, 2 ));
  2582     finally
  2583       TmpSL. Free;
  2584     end;
  2585   end;
  2586  
  2587   function T TemplateDi alogEntry. StripCode( var txt: s tring; cod e: char):  boolean;
  2588   var
  2589     p: integ er;
  2590   begin
  2591     p := pos (code, txt );
  2592     Result : = (p > 0);
  2593     if Resul t then
  2594     begin
  2595       while  p > 0 do
  2596       begin
  2597         dele te(txt, p,  1);
  2598         p :=  pos(code,  txt);
  2599       end;
  2600     end;
  2601   end;
  2602  
  2603   procedure  TTemplateD ialogEntry .UpDownCha nge(Sender : TObject) ;
  2604   begin
  2605     EnsureTe xt(TEdit(S ender), TU pDown(TEdi t(Sender). Tag));
  2606     DoChange (Sender);
  2607   end;
  2608  
  2609   function S tripEmbedd ed(iItems:  string):  string;
  2610   {7/26/01     S Monson
  2611                Returns  the field  will all e mbedded fi elds remov ed}
  2612   var
  2613     p1, p2,  icur: inte ger;
  2614   Begin
  2615     p1 := po s(Template FieldBegin Signature, iItems);
  2616     icur :=  0;
  2617     while p1  > 0 do
  2618       begin
  2619         p2 : = pos(Temp lateFieldE ndSignatur e,copy(iIt ems,icur+p 1+Template FieldSigna tureLen,ma xint));
  2620         if   p2 > 0 the n
  2621           be gin
  2622              delete(iIt ems,p1+icu r,Template FieldSigna tureLen+p2 +TemplateF ieldSignat ureEndLen- 1);
  2623              icur := ic ur + p1 -  1;
  2624              p1 := pos( TemplateFi eldBeginSi gnature,co py(iItems, icur+1,max int));
  2625           en d
  2626         else
  2627           p1  := 0;
  2628       end;
  2629     Result : = iItems;
  2630   end;
  2631  
  2632   procedure  StripScree nReaderCod es(var Tex t: string) ;
  2633   var
  2634     p, j: in teger;
  2635   begin
  2636     for j :=  low(Scree nReaderCod es) to hig h(ScreenRe aderCodes)  do
  2637     begin
  2638       p := 1 ;
  2639       while  (p > 0) do
  2640       begin
  2641         p :=  posex(Scr eenReaderC odes[j], T ext, p);
  2642         if p  > 0 then
  2643           de lete(Text,  p, Screen ReaderCode Lens[j]);
  2644       end;
  2645     end;
  2646   end;
  2647  
  2648   procedure  StripScree nReaderCod es(SL: TSt rings);
  2649   var
  2650     temp: st ring;
  2651     i: integ er;
  2652  
  2653   begin
  2654     for i :=  0 to SL.C ount - 1 d o
  2655     begin
  2656       temp : = SL[i];
  2657       StripS creenReade rCodes(tem p);
  2658       SL[i]  := temp;
  2659     end;
  2660   end;
  2661  
  2662   function H asScreenRe aderBreakC odes(SL: T Strings):  boolean;
  2663   var
  2664     i: integ er;
  2665  
  2666   begin
  2667     Result : = TRUE;
  2668     for i :=  0 to SL.C ount - 1 d o
  2669     begin
  2670       if pos (ScreenRea derCodeSig nature, SL [i]) > 0 t hen
  2671         exit ;
  2672     end;
  2673     Result : = FALSE;
  2674   end;
  2675  
  2676   // NSR2010 0706 AA 20 150706 --- ---------- ---------- ---------- ---------- ---- begin
  2677   function T TemplateDi alogEntry. GetControl (CtrlID: i nteger): T Control;
  2678   Var
  2679    I: Intege r;
  2680    Ctrl: TCo ntrol;
  2681   begin
  2682    Result :=  nil;
  2683    for i :=  0 to FCont rols.Count -1 do
  2684     begin
  2685       Ctrl : = TControl (FControls .Objects[i ]);
  2686       if(ass igned(Ctrl )) and (Ct rl.Tag = C trlID) the n
  2687        Resul t := Ctrl;
  2688     end;
  2689   end;
  2690   // NSR2010 0706 AA 20 150706 --- ---------- ---------- ---------- ---------- ------ end
  2691  
  2692   initializa tion
  2693  
  2694   finalizati on
  2695     KillObj( @uTmplFlds , TRUE);
  2696     KillObj( @uEntries,  TRUE);
  2697  
  2698   end.