40. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 2/17/2017 12:43:23 PM Central Standard 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.

40.1 Files compared

# Location File Last Modified
1 CPRS_V32_T20_cif.zip\OR_30_405V20_SRC.zip\CPRS-chart\Templates uTemplateFields.pas Thu Dec 15 14:28:32 2016 UTC
2 CPRS_V32_T20_cif.zip\OR_30_405V20_SRC.zip\CPRS-chart\Templates uTemplateFields.pas Fri Feb 17 17:22:02 2017 UTC

40.2 Comparison summary

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

40.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

40.4 Active regular expressions

No regular expressions were active.

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