40. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 2/23/2017 7:16:42 AM 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_v31_223_cif.zip\OR_30_377V223_SRC.zip\CPRS-chart\Templates uTemplateFields.pas Wed Nov 16 17:31:42 2016 UTC
2 CPRS_v31_223_cif.zip\OR_30_377V223_SRC.zip\CPRS-chart\Templates uTemplateFields.pas Fri Feb 17 20:25:43 2017 UTC

40.2 Comparison summary

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