source: cprs/branches/foia-cprs/CPRS-Chart/Templates/fTemplateDialog.pas@ 459

Last change on this file since 459 was 459, checked in by Kevin Toppenberg, 16 years ago

Adding foia-cprs branch

File size: 20.4 KB
Line 
1unit fTemplateDialog;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 StdCtrls, ExtCtrls, ORCtrls, ORFn, AppEvnts, uTemplates;
8
9type
10 TfrmTemplateDialog = class(TForm)
11 sbMain: TScrollBox;
12 pnlBottom: TPanel;
13 btnCancel: TButton;
14 btnOK: TButton;
15 btnAll: TButton;
16 btnNone: TButton;
17 lblFootnote: TStaticText;
18 btnPreview: TButton;
19 procedure btnAllClick(Sender: TObject);
20 procedure btnNoneClick(Sender: TObject);
21 procedure FormPaint(Sender: TObject);
22 procedure FormCreate(Sender: TObject);
23 procedure FormDestroy(Sender: TObject);
24 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
25 procedure btnOKClick(Sender: TObject);
26 procedure btnPreviewClick(Sender: TObject);
27 procedure FormClose(Sender: TObject; var Action: TCloseAction);
28 private
29 SL: TStrings;
30 BuildIdx: TStringList;
31 Entries: TStringList;
32 NoTextID: TStringList;
33 Index: string;
34 OneOnly: boolean;
35 Count: integer;
36 RepaintBuild: boolean;
37 FirstIndent: integer;
38 FBuilding: boolean;
39 FOldHintEvent: TShowHintEvent;
40 FMaxPnlWidth: integer;
41 FTabPos: integer;
42 FCheck4Required: boolean;
43 FSilent: boolean;
44 procedure ChkAll(Chk: boolean);
45 procedure BuildCB(CBidx: integer; var Y: integer; FirstTime: boolean);
46 procedure ItemChecked(Sender: TObject);
47 procedure BuildAllControls;
48 procedure AppShowHint(var HintStr: string; var CanShow: Boolean;
49 var HintInfo: THintInfo);
50 procedure FieldChanged(Sender: TObject);
51 procedure EntryDestroyed(Sender: TObject);
52 function GetObjectID( Control: TControl): string;
53 function GetParentID( Control: TControl): string;
54 function FindObjectByID( id: string): TControl;
55 function IsAncestor( OldID: string; NewID: string): boolean;
56 procedure ParentCBEnter(Sender: TObject);
57 procedure ParentCBExit(Sender: TObject);
58 public
59 property Silent: boolean read FSilent write FSilent ;
60 published
61 end;
62
63// Returns True if Cancel button is pressed
64function DoTemplateDialog(SL: TStrings; const CaptionText: string; PreviewMode: boolean = FALSE): boolean;
65procedure CheckBoilerplate4Fields(SL: TStrings; const CaptionText: string = ''; PreviewMode: boolean = FALSE); overload;
66procedure CheckBoilerplate4Fields(var AText: string; const CaptionText: string = ''; PreviewMode: boolean = FALSE); overload;
67
68var
69 frmTemplateDialog: TfrmTemplateDialog;
70
71implementation
72
73uses dShared, uConst, uTemplateFields, fRptBox, uInit;
74
75{$R *.DFM}
76
77const
78 Gap = 4;
79 IndentGap = 18;
80
81
82procedure GetText(SL: TStrings; IncludeEmbeddedFields: Boolean);
83var
84 i, p1, p2: integer;
85 Txt, tmp: string;
86 Save, Hidden: boolean;
87 TmpCtrl: TStringList;
88
89begin
90 Txt := SL.Text;
91 SL.Clear;
92 TmpCtrl := TStringList.Create;
93 try
94 for i := 0 to frmTemplateDialog.sbMain.ControlCount-1 do
95 with frmTemplateDialog.sbMain do
96 begin
97 tmp := IntToStr(Controls[i].Tag);
98 tmp := StringOfChar('0', 7-length(tmp)) + tmp;
99 TmpCtrl.AddObject(tmp, Controls[i]);
100 end;
101 TmpCtrl.Sort;
102 for i := 0 to TmpCtrl.Count-1 do
103 begin
104 Save := FALSE;
105 if(TmpCtrl.Objects[i] is TORCheckBox) and (TORCheckBox(TmpCtrl.Objects[i]).Checked) then
106 Save := TRUE
107 else
108 if(frmTemplateDialog.OneOnly and (TmpCtrl.Objects[i] is TPanel)) then
109 Save := TRUE;
110 if(Save) then
111 begin
112 tmp := Piece(frmTemplateDialog.Index,U,TControl(TmpCtrl.Objects[i]).Tag);
113 p1 := StrToInt(Piece(tmp,'~',1));
114 p2 := StrToInt(Piece(tmp,'~',2));
115 Hidden := (copy(Piece(tmp,'~',3),2,1)=BOOLCHAR[TRUE]);
116 SL.Text := SL.Text + ResolveTemplateFields(Copy(Txt,p1,p2), FALSE, Hidden, IncludeEmbeddedFields);
117 end;
118 end;
119 finally
120 TmpCtrl.Free;
121 end;
122end;
123
124// Returns True if Cancel button is pressed
125function DoTemplateDialog(SL: TStrings; const CaptionText: string; PreviewMode: boolean = FALSE): boolean;
126var
127 i, j, idx, Indent: integer;
128 DlgProps, Txt: string;
129 DlgIDCounts: TStringList;
130 DlgInt: TIntStruc;
131 CancelDlg: Boolean;
132 CancelMsg: String;
133
134
135 procedure IncDlgID(var id: string); //Appends an item count in the form of id.0, id.1, id.2, etc
136 var //based on what is in the StringList for id.
137 k: integer;
138
139 begin
140 k := DlgIDCounts.IndexOf(id);
141
142 if (k >= 0) then
143 begin
144 DlgInt := TIntStruc(DlgIDCounts.Objects[k]);
145 DlgInt.x := DlgInt.x + 1;
146 id := id + '.' + InttoStr(DlgInt.x);
147 end
148 else
149 begin
150 DlgInt := TIntStruc.Create;
151 DlgInt.x := 0;
152 DlgIDCounts.AddObject(id, DlgInt);
153 id := id + '.0';
154 end;
155
156 end;
157
158 procedure CountDlgProps(var DlgID: string); //Updates the item and parent item id's with the count
159 var // value id.0, id.1, id.2, id.3, etc. The input dialog
160 x: integer; // id is in the form 'a;b;c;d', where c is the item id
161 id, pid: string; // and d is the parent item id
162
163 begin
164 id := piece(DlgID,';',3);
165 pid := piece(DlgID,';',4);
166
167 if length(pid) > 0 then
168 x := DlgIDCounts.IndexOf(pid)
169 else
170 x := -1;
171
172 if (x >= 0) then
173 begin
174 DlgInt := TIntStruc(DlgIDCounts.Objects[x]);
175 pid := pid + '.' + InttoStr(DlgInt.x);
176 end;
177
178 if length(id) > 0 then
179 IncDlgID(id);
180
181 SetPiece(DlgID,';',3,id);
182 SetPiece(DlgID,';',4,pid);
183 end;
184
185begin
186 Result := FALSE;
187 CancelDlg := FALSE;
188 frmTemplateDialog := TfrmTemplateDialog.Create(Application);
189 try
190 DlgIDCounts := TStringList.Create;
191 DlgIDCounts.Sorted := TRUE;
192 DlgIDCounts.Duplicates := dupError;
193 frmTemplateDialog.Caption := CaptionText;
194 AssignFieldIDs(SL);
195 frmTemplateDialog.SL := SL;
196 frmTemplateDialog.Index := '';
197 Txt := SL.Text;
198 frmTemplateDialog.OneOnly := (DelimCount(Txt, ObjMarker) = 1);
199 frmTemplateDialog.Count := 0;
200 idx := 1;
201 frmTemplateDialog.FirstIndent := 99999;
202 repeat
203 i := pos(ObjMarker, Txt);
204 if(i > 1) then
205 begin
206 j := pos(DlgPropMarker, Txt);
207 if(j > 0) then
208 begin
209 DlgProps := copy(Txt, j + DlgPropMarkerLen, (i - j - DlgPropMarkerLen));
210 CountDlgProps(DlgProps);
211 end
212 else
213 begin
214 DlgProps := '';
215 j := i;
216 end;
217 inc(frmTemplateDialog.Count);
218 frmTemplateDialog.Index := frmTemplateDialog.Index +
219 IntToStr(idx)+'~'+IntToStr(j-1)+'~'+DlgProps+U;
220 inc(idx,i+ObjMarkerLen-1);
221 Indent := StrToIntDef(Piece(DlgProps, ';', 5),0);
222 if(frmTemplateDialog.FirstIndent > Indent) then
223 frmTemplateDialog.FirstIndent := Indent;
224 end;
225 if(i > 0) then
226 delete(txt, 1, i + ObjMarkerLen - 1);
227 until (i = 0);
228 if(frmTemplateDialog.Count > 0) then
229 begin
230 if(frmTemplateDialog.OneOnly) then
231 begin
232 frmTemplateDialog.btnNone.Visible := FALSE;
233 frmTemplateDialog.btnAll.Visible := FALSE;
234 end;
235 frmTemplateDialog.BuildAllControls;
236 repeat
237 frmTemplateDialog.ShowModal;
238 if(frmTemplateDialog.ModalResult = mrOK) then
239 GetText(SL, TRUE) {TRUE = Include embedded fields}
240 else
241 if (not PreviewMode) and (not frmTemplateDialog.Silent) and (not uInit.TimedOut) then
242 begin
243 CancelMsg := 'If you cancel, your changes will not be saved. Are you sure you want to cancel?';
244 if (InfoBox(CancelMsg, 'Cancel Dialog Processing', MB_YESNO or MB_DEFBUTTON2 or MB_ICONQUESTION) = ID_YES) then
245 begin
246 SL.Clear;
247 Result := TRUE;
248 CancelDlg := TRUE;
249 end
250 else
251 CancelDlg := FALSE;
252 end
253 else
254 begin
255 SL.Clear;
256 Result := TRUE;
257 CancelDlg := TRUE;
258 end;
259 until CancelDlg or (frmTemplateDialog.ModalResult = mrOK)
260 end
261 else
262 SL.Clear;
263 finally
264 //frmTemplateDialog.Free; v22.11e RV
265 frmTemplateDialog.Release;
266 //frmTemplateDialog := nil; access violation source? removed 7/28/03 RV
267 for i := 0 to DlgIDCounts.Count-1 do begin
268 DlgIDCounts.Objects[i].Free;
269 end;
270 DlgIDCounts.Free;
271 end;
272
273 if not Result then
274 CheckBoilerplate4Fields(SL, CaptionText, PreviewMode);
275
276end;
277
278procedure CheckBoilerplate4Fields(SL: TStrings; const CaptionText: string = ''; PreviewMode: boolean = FALSE);
279begin
280 while(HasTemplateField(SL.Text)) do
281 begin
282 if (BoilerplateTemplateFieldsOK(SL.Text)) then
283 begin
284 SL[SL.Count-1] := SL[SL.Count-1] + DlgPropMarker + '00100;0;-1;;0' + ObjMarker;
285 DoTemplateDialog(SL, CaptionText, PreviewMode);
286 end
287 else
288 SL.Clear;
289 end;
290end;
291
292procedure CheckBoilerplate4Fields(var AText: string; const CaptionText: string = ''; PreviewMode: boolean = FALSE);
293var
294 tmp: TStringList;
295
296begin
297 tmp := TStringList.Create;
298 try
299 tmp.text := AText;
300 CheckBoilerplate4Fields(tmp, CaptionText, PreviewMode);
301 AText := tmp.text;
302 finally
303 tmp.free;
304 end;
305end;
306
307procedure TfrmTemplateDialog.ChkAll(Chk: boolean);
308var
309 i: integer;
310
311begin
312 for i := 0 to sbMain.ControlCount-1 do
313 begin
314 if(sbMain.Controls[i] is TORCheckBox) then
315 TORCheckBox(sbMain.Controls[i]).Checked := Chk;
316 end;
317end;
318
319procedure TfrmTemplateDialog.btnAllClick(Sender: TObject);
320begin
321 ChkAll(TRUE);
322end;
323
324procedure TfrmTemplateDialog.btnNoneClick(Sender: TObject);
325begin
326 ChkAll(FALSE);
327end;
328
329function TfrmTemplateDialog.GetObjectID( Control: TControl): string;
330var
331 idx, idx2: integer;
332begin
333 result := '';
334 if Assigned(Control) then
335 begin
336 idx := Control.Tag;
337 if(idx > 0) then
338 begin
339 idx2 := BuildIdx.IndexOfObject(TObject(idx));
340 if idx2 >= 0 then
341 result := BuildIdx[idx2]
342 else
343 result := Piece(Piece(Piece(Index, U, idx),'~',3), ';', 3);
344 end;
345 end;
346end;
347
348function TfrmTemplateDialog.GetParentID( Control: TControl): string;
349var
350 idx: integer;
351begin
352 result := '';
353 if Assigned(Control) then
354 begin
355 idx := Control.Tag;
356 if(idx > 0) then
357 result := Piece(Piece(Piece(Index, U, idx),'~',3), ';', 4);
358 end;
359end;
360
361function TfrmTemplateDialog.FindObjectByID( id: string): TControl;
362var
363 i: integer;
364 ObjID: string;
365begin
366 result := nil;
367 if ID <> '' then
368 begin
369 for i := 0 to sbMain.ControlCount-1 do
370 begin
371 ObjID := GetObjectID(sbMain.Controls[i]);
372 if(ObjID = ID) then
373 begin
374 result := sbMain.Controls[i];
375 break;
376 end;
377 end;
378 end;
379end;
380
381function TfrmTemplateDialog.IsAncestor( OldID: string; NewID: string): boolean;
382begin
383 if (OldID = '') or (NewID = '') then
384 result := False
385 else if OldID = NewID then
386 result := True
387 else
388 result := IsAncestor(OldID, GetParentID(FindObjectByID(NewID)));
389end;
390
391procedure TfrmTemplateDialog.BuildCB(CBidx: integer; var Y: integer; FirstTime: boolean);
392var
393 bGap, Indent, i, idx, idx2, p1, p2: integer;
394 EID, ID, PID, DlgProps, tmp, txt, tmpID, ObjID: string;
395 pctrl, ctrl: TControl;
396 pnl: TPanel;
397 KillCtrl, doHint, dsp, noTextParent: boolean;
398 Entry: TTemplateDialogEntry;
399 StringIn, StringOut: string;
400
401 procedure NextTabCtrl(ACtrl: TControl);
402 begin
403 if(ACtrl is TWinControl) then
404 begin
405 inc(FTabPos);
406 TWinControl(ACtrl).TabOrder := FTabPos;
407 end;
408 end;
409
410begin
411 tmp := Piece(Index, U, CBidx);
412 p1 := StrToInt(Piece(tmp,'~',1));
413 p2 := StrToInt(Piece(tmp,'~',2));
414 DlgProps := Piece(tmp,'~',3);
415 ID := Piece(DlgProps, ';', 3);
416 PID := Piece(DlgProps, ';', 4);
417
418 ctrl := nil;
419 pctrl := nil;
420 if(PID <> '') then
421 noTextParent := (NoTextID.IndexOf(PID) < 0)
422 else
423 noTextParent := TRUE;
424 if not FirstTime then
425 ctrl := FindObjectByID(ID);
426 if noTextParent and (PID <> '') then
427 pctrl := FindObjectByID(PID);
428 if(PID = '') then
429 KillCtrl := FALSE
430 else
431 begin
432 if(assigned(pctrl)) then
433 begin
434 if(not (pctrl is TORCheckBox)) or
435 (copy(DlgProps,3,1) = BOOLCHAR[TRUE]) then // show if parent is unchecked
436 KillCtrl := FALSE
437 else
438 KillCtrl := (not TORCheckBox(pctrl).Checked);
439 end
440 else
441 KillCtrl := noTextParent;
442 end;
443 if KillCtrl then
444 begin
445 if(assigned(ctrl)) then
446 begin
447 if(ctrl is TORCheckBox) and (assigned(TORCheckBox(ctrl).Associate)) then
448 TORCheckBox(ctrl).Associate.Hide;
449 idx := BuildIdx.IndexOfObject(TObject(ctrl.Tag));
450 if idx >= 0 then
451 BuildIdx.delete(idx);
452 ctrl.Free;
453 end;
454 exit;
455 end;
456 tmp := copy(SL.Text, p1, p2);
457 if(copy(tmp, length(tmp)-1, 2) = CRLF) then
458 delete(tmp, length(tmp)-1, 2);
459 bGap := StrToIntDef(copy(DlgProps,5,1),0);
460 while bGap > 0 do
461 begin
462 if(copy(tmp, 1, 2) = CRLF) then
463 begin
464 delete(tmp, 1, 2);
465 dec(bGap);
466 end
467 else
468 bGap := 0;
469 end;
470 if(tmp = NoTextMarker) then
471 begin
472 if(NoTextID.IndexOf(ID) < 0) then
473 NoTextID.Add(ID);
474 exit;
475 end;
476 if(not assigned(ctrl)) then
477 begin
478 dsp := (copy(DlgProps,1,1)=BOOLCHAR[TRUE]);
479 EID := 'DLG' + IntToStr(CBIdx);
480 idx := Entries.IndexOf(EID);
481 doHint := FALSE;
482 txt := tmp;
483 if(idx < 0) then
484 begin
485 if(copy(DlgProps,2,1)=BOOLCHAR[TRUE]) then // First Line Only
486 begin
487 i := pos(CRLF, tmp);
488 if(i > 0) then
489 begin
490 dec(i);
491 if i > 70 then
492 begin
493 i := 71;
494 while (i > 0) and (tmp[i] <> ' ') do dec(i);
495 if i = 0 then
496 i := 70
497 else
498 dec(i);
499 end;
500 doHint := TRUE;
501 tmp := copy(tmp, 1, i) + ' ...';
502 end;
503 end;
504 Entry := GetDialogEntry(sbMain, EID, tmp);
505 Entry.AutoDestroyOnPanelFree := TRUE;
506 Entry.OnDestroy := EntryDestroyed;
507 Entries.AddObject(EID, Entry);
508 end
509 else
510 Entry := TTemplateDialogEntry(Entries.Objects[idx]);
511
512 pnl := Entry.GetPanel(FMaxPnlWidth, sbMain);
513 pnl.Show;
514 if(doHint and (not pnl.ShowHint)) then
515 begin
516 pnl.ShowHint := TRUE;
517 Entry.Obj := pnl;
518 Entry.Text := txt;
519 pnl.hint := Entry.GetText;
520 Entry.OnChange := FieldChanged;
521 end;
522 if(dsp or OneOnly) then
523 ctrl := pnl
524 else
525 begin
526 ctrl := TORCheckBox.Create(Self);
527 ctrl.Parent := sbMain;
528
529 TORCheckbox(ctrl).OnEnter := frmTemplateDialog.ParentCBEnter;
530 TORCheckbox(ctrl).OnExit := frmTemplateDialog.ParentCBExit;
531
532 TORCheckBox(ctrl).Height := TORCheckBox(ctrl).Height + 5;
533 TORCheckBox(ctrl).Width := 17;
534
535 {Insert next line when focus fixed}
536 // ctrl.Width := IndentGap;
537 {Remove next line when focus fixed}
538 TORCheckBox(ctrl).AutoSize := false;
539 TORCheckBox(ctrl).Associate := pnl;
540 tmpID := copy(ID, 1, (pos('.', ID) - 1)); {copy the ID without the decimal place}
541 if Templates.IndexOf(tmpID) > -1 then
542 StringIn := 'Sub-Template: ' + TTemplate(Templates.Objects[Templates.IndexOf(tmpID)]).PrintName
543 else
544 StringIn := 'Sub-Template:';
545 StringOut := StringReplace(StringIn, '&', '&&', [rfReplaceAll]);
546 TORCheckBox(ctrl).Caption := StringOut;
547
548 end;
549 ctrl.Tag := CBIdx;
550
551 Indent := StrToIntDef(Piece(DlgProps, ';', 5),0) - FirstIndent;
552 if dsp then inc(Indent);
553 ctrl.Left := Gap + (Indent * IndentGap);
554 //ctrl.Width := sbMain.ClientWidth - Gap - ctrl.Left - ScrollBarWidth;
555 if(ctrl is TORCheckBox) then
556 pnl.Left := ctrl.Left + IndentGap;
557
558 if(ctrl is TORCheckBox) then with TORCheckBox(ctrl) do
559 begin
560 GroupIndex := StrToIntDef(Piece(DlgProps, ';', 2),0);
561 if(GroupIndex <> 0) then
562 RadioStyle := TRUE;
563 OnClick := ItemChecked;
564 StringData := DlgProps;
565 end;
566 if BuildIdx.IndexOfObject(TObject(CBIdx)) < 0 then
567 BuildIdx.AddObject(Piece(Piece(Piece(Index, U, CBIdx),'~',3), ';', 3), TObject(CBIdx));
568 end;
569 ctrl.Top := Y;
570 NextTabCtrl(ctrl);
571 if(ctrl is TORCheckBox) then
572 begin
573 TORCheckBox(ctrl).Associate.Top := Y;
574 NextTabCtrl(TORCheckBox(ctrl).Associate);
575 inc(Y, TORCheckBox(ctrl).Associate.Height+1);
576 end
577 else
578 inc(Y, ctrl.Height+1);
579end;
580
581procedure TfrmTemplateDialog.ParentCBEnter(Sender: TObject);
582begin
583 (Sender as TORCheckbox).FocusOnBox := true;
584end;
585
586procedure TfrmTemplateDialog.ParentCBExit(Sender: TObject);
587begin
588 (Sender as TORCheckbox).FocusOnBox := false;
589
590end;
591
592procedure TfrmTemplateDialog.ItemChecked(Sender: TObject);
593begin
594 if(copy(TORCheckBox(Sender).StringData,4,1) = '1') then
595 begin
596 RepaintBuild := TRUE;
597 Invalidate;
598 end;
599end;
600
601procedure TfrmTemplateDialog.BuildAllControls;
602var
603 i, Y: integer;
604 FirstTime: boolean;
605
606begin
607 if FBuilding then exit;
608 FBuilding := TRUE;
609 try
610 FTabPos := 0;
611 FirstTime := (sbMain.ControlCount = 0);
612 NoTextID.Clear;
613 Y := Gap - sbMain.VertScrollBar.Position;
614 for i := 1 to Count do
615 BuildCB(i, Y, FirstTime);
616 finally
617 FBuilding := FALSE;
618 end;
619end;
620
621procedure TfrmTemplateDialog.FormPaint(Sender: TObject);
622begin
623 if RepaintBuild then
624 begin
625 RepaintBuild := FALSE;
626 BuildAllControls;
627 end;
628end;
629
630procedure TfrmTemplateDialog.FormCreate(Sender: TObject);
631begin
632 BuildIdx := TStringList.Create;
633 Entries := TStringList.Create;
634 NoTextID := TStringList.Create;
635 FOldHintEvent := Application.OnShowHint;
636 Application.OnShowHint := AppShowHint;
637 ResizeAnchoredFormToFont(Self);
638 FMaxPnlWidth := FontWidthPixel(sbMain.Font.Handle) * MAX_ENTRY_WIDTH; //AGP change Template Dialog to wrap at 80 instead of 74
639end;
640
641procedure TfrmTemplateDialog.AppShowHint(var HintStr: string;
642 var CanShow: Boolean; var HintInfo: THintInfo);
643const
644 HistHintDelay = 1200000; // 20 minutes
645
646begin
647// if(HintInfo.HintControl.Parent = sbMain) then
648 HintInfo.HideTimeout := HistHintDelay;
649 if(assigned(FOldHintEvent)) then
650 FOldHintEvent(HintStr, CanShow, HintInfo);
651end;
652
653procedure TfrmTemplateDialog.FormDestroy(Sender: TObject);
654begin
655 //Application.OnShowHint := FOldHintEvent; v22.11f - RV - moved to OnClose
656 NoTextID.Free;
657 FreeEntries(Entries);
658 Entries.Free;
659 BuildIdx.Free;
660end;
661
662procedure TfrmTemplateDialog.FieldChanged(Sender: TObject);
663begin
664 with TTemplateDialogEntry(Sender) do
665 TPanel(Obj).hint := GetText;
666end;
667
668procedure TfrmTemplateDialog.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
669var
670 Txt, tmp: string;
671 i, p1, p2: integer;
672 Save: boolean;
673
674begin
675 CanClose := TRUE;
676 if FCheck4Required then
677 begin
678 FCheck4Required := FALSE;
679 Txt := SL.Text;
680 for i := 0 to sbMain.ControlCount-1 do
681 begin
682 Save := FALSE;
683 if(sbMain.Controls[i] is TORCheckBox) and
684 (TORCheckBox(sbMain.Controls[i]).Checked) then
685 Save := TRUE
686 else
687 if(OneOnly and (sbMain.Controls[i] is TPanel)) then
688 Save := TRUE;
689 if(Save) then
690 begin
691 tmp := Piece(Index,U,sbMain.Controls[i].Tag);
692 p1 := StrToInt(Piece(tmp,'~',1));
693 p2 := StrToInt(Piece(tmp,'~',2));
694 if AreTemplateFieldsRequired(Copy(Txt,p1,p2)) then
695 CanClose := FALSE;
696 end;
697 if not CanClose then
698 begin
699 ShowMessage(MissingFieldsTxt);
700 break;
701 end;
702 end;
703 end;
704end;
705
706procedure TfrmTemplateDialog.btnOKClick(Sender: TObject);
707begin
708 FCheck4Required := TRUE;
709end;
710
711procedure TfrmTemplateDialog.btnPreviewClick(Sender: TObject);
712var
713 TmpSL: TStringList;
714
715begin
716 TmpSL := TStringList.Create;
717 try
718 TmpSL.Assign(SL);
719 GetText(TmpSL, FALSE); {FALSE = Do not include embedded fields}
720 ReportBox(TmpSL, 'Dialog Preview', FALSE);
721 finally
722 TmpSL.Free;
723 end;
724end;
725
726procedure TfrmTemplateDialog.EntryDestroyed(Sender: TObject);
727var
728 idx: integer;
729
730begin
731 idx := Entries.IndexOf(TTemplateDialogEntry(Sender).ID);
732 if idx >= 0 then
733 Entries.delete(idx);
734end;
735
736procedure TfrmTemplateDialog.FormClose(Sender: TObject;
737 var Action: TCloseAction);
738begin
739 Application.OnShowHint := FOldHintEvent;
740end;
741
742end.
743
Note: See TracBrowser for help on using the repository browser.