Procedure

SaveTemplate

Module

uTemplates

Last Modified

7/15/2014 3:26:44 PM

Scope

Interfaced

Declaration

procedure SaveTemplate(Template: TTemplate; Idx: integer; ErrorList: TStrings = nil);

Calls Hierarchy


SaveTemplate
 ├TTemplate.Changed
 │ ├TTemplate.ValidID
 │ └TTemplate.ItemIENs
 │   └TTemplate.GetItems
 │     └ExpandTemplate
 │       ├TTemplate.GetChildren
 │       ├GetTemplateChildren
 │       ├AddTemplate
 │       │ ├TTemplate.Create
 │       │ │ └TTemplate.ReminderDialogIEN
 │       │ └TTemplate.AddChild
 │       │   └TTemplate.GetItems...
 │       └TTemplate.ItemIENs...
 ├TTemplate.Unlock
 │ ├TTemplate.ValidID
 │ └UnlockTemplate
 ├TTemplate.GetBoilerplate
 │ └GetTemplateBoilerplate
 ├TTemplate.ReminderDialogIEN
 ├TTemplate.GetDescription
 │ └LoadTemplateDescription
 ├UpdateTemplate
 │ └UpdateTIURec
 ├DisplayErrors
 └TTemplate.ClearBackup
   └TTemplate.ItemIENs...

Called-By Hierarchy


                            SaveTemplate
                      SaveAllTemplates┤ 
    TfrmTemplateEditor.btnApplyClick┤ │ 
TfrmTemplateEditor.mnuRefreshClick┘ │ │ 
       TfrmTemplateEditor.btnOKClick┤ │ 
   TfrmTemplateEditor.FormCloseQuery┘ │ 
          TfrmTemplateEditor.InitTrees┘ 
       TfrmTemplateEditor.FormCreate┤   
      TfrmTemplateEditor.RefreshData┘   
TfrmTemplateEditor.mnuRefreshClick┘     

Calls

Name Declaration Comments
TTemplate.Changed function Changed: boolean; -
TTemplate.ClearBackup procedure ClearBackup(ClearItemIENs: boolean = TRUE); -
DisplayErrors procedure DisplayErrors(Errors: TStringList; SingleError: string = ''); -
TTemplate.GetBoilerplate function GetBoilerplate: string; -
TTemplate.GetDescription function GetDescription: string; -
TTemplate.ReminderDialogIEN function ReminderDialogIEN: string; -
TTemplate.Unlock procedure Unlock; -
UpdateTemplate function UpdateTemplate(ID: string; Fields: TStrings): string; -

Called-By

Name Declaration Comments
TfrmTemplateEditor.InitTrees procedure InitTrees; -
SaveAllTemplates function SaveAllTemplates: boolean; -


Source

750   procedure SaveTemplate(Template: TTemplate; Idx: integer; ErrorList: TStrings = nil);
751   var
752     i: integer;
753     ID, Tmp: string;
754     NoCheck: boolean;
755     DescSL: TStringList;
756   
757   begin
758   { Removed because this may be a bug??? - what if it's hidden? -
759     better to save and delete than miss it
760   //Don't save new templates that have been deleted
761     if(((Template.ID = '0') or (Template.ID = '')) and
762        (Template.Nodes.Count = 0)) then exit;
763   }
764     if(not Template.Changed) then
765     begin
766       Template.Unlock;
767       exit;
768     end;
769   
770     if(not assigned(TempSL)) then
771       TempSL := TStringList.Create;
772     TempSL.Clear;
773     ID := Template.ID;
774   
775     NoCheck := (ID = '0') or (ID = '');
776   
777     with Template,Template.FBkup do
778     begin
779       if(NoCheck or (SavedBoilerplate and (BBoilerplate <> Boilerplate))) then
780       begin
781         TempSL.Text := BoilerPlate;
782         if(TempSL.Count > 0) then
783         begin
784           for i := 0 to TempSL.Count-1 do
785             TempSL[i] := '2,'+IntToStr(i+1)+',0='+TempSL[i];
786         end
787         else
788           TempSL.Add('2,1=@');
789       end;
790   
791       if(NoCheck or (SavedPrintName and (BPrintName <> PrintName))) then
792         TempSL.Add('.01='+PrintName);
793   
794       if(NoCheck or (SavedGap and (BGap <> Gap))) then
795       begin
796         if Gap = 0 then
797           TempSL.Add('.02=@')
798         else
799           TempSL.Add('.02='+IntToStr(Gap));
800       end;
801   
802       if(NoCheck or (SavedRealType and (BRealType <> RealType))) then
803         TempSL.Add('.03='+TemplateTypeCodes[RealType]);
804   
805       if(NoCheck or (SavedActive and (BActive <> Active))) then
806         TempSL.Add('.04='+TemplateActiveCode[Active]);
807   
808       if(NoCheck or (SavedExclude and (BExclude <> FExclude))) then
809         TempSL.Add('.05='+BOOLCHAR[Exclude]);
810   
811       if(NoCheck or (SavedDialog and (BDialog <> FDialog))) then
812         TempSL.Add('.08='+BOOLCHAR[Dialog]);
813   
814       if(NoCheck or (SavedDisplayOnly and (BDisplayOnly <> DisplayOnly))) then
815         TempSL.Add('.09='+BOOLCHAR[DisplayOnly]);
816   
817       if(NoCheck or (SavedFirstLine and (BFirstLine <> FirstLine))) then
818         TempSL.Add('.1='+BOOLCHAR[FirstLine]);
819   
820       if(NoCheck or (SavedOneItemOnly and (BOneItemOnly <> OneItemOnly))) then
821         TempSL.Add('.11='+BOOLCHAR[OneItemOnly]);
822   
823       if(NoCheck or (SavedHideDlgItems and (BHideDlgItems <> HideDlgItems))) then
824         TempSL.Add('.12='+BOOLCHAR[HideDlgItems]);
825   
826       if(NoCheck or (SavedHideItems and (BHideItems <> HideItems))) then
827         TempSL.Add('.13='+BOOLCHAR[HideItems]);
828   
829       if(NoCheck or (SavedIndentItems and (BIndentItems <> IndentItems))) then
830         TempSL.Add('.14='+BOOLCHAR[IndentItems]);
831   
832       if(NoCheck or (SavedReminderDialog and (BReminderDialog <> ReminderDialog))) then
833       begin
834         if ReminderDialogIEN = '' then
835           TempSL.Add('.15=@')
836         else
837           TempSL.Add('.15='+ReminderDialogIEN);
838       end;
839   
840       if(NoCheck or (SavedLock and (BLock <> Lock))) then
841         TempSL.Add('.16='+BOOLCHAR[Lock]);
842   
843       if(NoCheck or (SavedCOMObject and (BCOMObject <> COMObject))) then
844       begin
845         if COMObject = 0 then
846           TempSL.Add('.17=@')
847         else
848           TempSL.Add('.17='+IntToStr(COMObject));
849       end;
850   
851       if(NoCheck or (SavedCOMParam and (BCOMParam <> COMParam))) then
852       begin
853         if COMParam = '' then
854           TempSL.Add('.18=@')
855         else
856           TempSL.Add('.18=' + COMParam);
857       end;
858   
859       if(NoCheck or (SavedFileLink and (BFileLink <> FileLink))) then
860       begin
861         if FileLink = '' then
862           TempSL.Add('.19=@')
863         else
864           TempSL.Add('.19=' + FileLink);
865       end;
866   
867       if(NoCheck or (SavedPersonalOwner and (BPersonalOwner <> PersonalOwner))) then
868       begin
869         if(PersonalOwner = 0) then
870           Tmp := ''
871         else
872           Tmp := IntToStr(PersonalOwner);
873         TempSL.Add('.06='+Tmp);
874       end;
875   
876       if(NoCheck or (SavedDescription and (BDescription <> Description))) then
877       begin
878         DescSL := TStringList.Create;
879         try
880           DescSL.Text := Description;
881           if(DescSL.Count > 0) then
882           begin
883             for i := 0 to DescSL.Count-1 do
884               DescSL[i] := '5,'+IntToStr(i+1)+',0='+DescSL[i];
885           end
886           else
887             DescSL.Add('5,1=@');
888           FastAddStrings(DescSL, TempSL)
889         finally
890           DescSL.Free;
891         end;
892       end;
893       
894     end;
895       
896     if(TempSL.Count > 0) then
897     begin
898       Tmp := UpdateTemplate(ID, TempSL);
899       if(Piece(Tmp,U,1) = '0') then
900       begin
901         Tmp := 'Error Saving ' + Template.PrintName + ' ' + ID + '=' + Tmp;
902         if(Assigned(ErrorList)) then
903           ErrorList.Add(Tmp)
904         else
905           DisplayErrors(nil, Tmp);
906       end
907       else
908       begin
909         if(((ID = '') or (ID = '0')) and (Tmp <> ID)) then
910         begin
911           if(idx < 0) then
912             idx := Templates.IndexOfObject(Template);
913           Template.FID := Tmp;
914           Templates[idx] := Tmp;
915           if assigned(Template.FNodes) then
916           begin
917             for i := 0 to Template.FNodes.Count-1 do
918               TORTreeNode(Template.FNodes.Objects[i]).StringData := Template.ID + U + Template.PrintName;
919           end;
920         end;
921         Template.ClearBackup(FALSE);
922         if NoCheck then with Template.FBkup do
923         begin
924           BItemIENs := '';
925           SavedItemIENs := TRUE;
926         end;
927       end;
928     end;
929   end;