source: cprs/trunk/CPRS-Chart/Templates/fTemplateDialog.pas@ 722

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

Initial Upload of Official WV CPRS 1.0.26.76

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