46. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 1/31/2019 1:51:42 PM Central Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

46.1 Files compared

# Location File Last Modified
1 CPRS v31b Phase 2 T257 CiF Submission..zip\CPRS v31b Phase 2 T257 CiF Submission\OR_30_377V257_src\Templates uTemplateFields.pas Thu Nov 15 18:27:48 2018 UTC
2 CPRS v31b Phase 2 T257 CiF Submission.zip\CPRS v31b Phase 2 T257 CiF Submission\OR_30_377V257_src\Templates uTemplateFields.pas Tue Jan 29 15:32:37 2019 UTC

46.2 Comparison summary

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

46.3 Comparison options

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

46.4 Active regular expressions

No regular expressions were active.

46.5 Comparison detail

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