source: cprs/branches/foia-cprs/CPRS-Chart/Templates/fTemplateFields.pas@ 711

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

Adding foia-cprs branch

File size: 4.0 KB
RevLine 
[459]1unit fTemplateFields;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 ORCtrls, ComCtrls, StdCtrls, ExtCtrls;
8
9type
10 TfrmTemplateFields = class(TForm)
11 pnlBottom: TPanel;
12 btnCancel: TButton;
13 cboObjects: TORComboBox;
14 btnInsert: TButton;
15 lblReq: TStaticText;
16 btnPreview: TButton;
17 procedure FormShow(Sender: TObject);
18 procedure FormCreate(Sender: TObject);
19 procedure cboObjectsNeedData(Sender: TObject; const StartFrom: String;
20 Direction, InsertAt: Integer);
21 procedure cboObjectsDblClick(Sender: TObject);
22 procedure btnCancelClick(Sender: TObject);
23 procedure FormClose(Sender: TObject; var Action: TCloseAction);
24 procedure btnInsertClick(Sender: TObject);
25 procedure btnPreviewClick(Sender: TObject);
26 procedure cboObjectsChange(Sender: TObject);
27 private
28{ Fre: TRichEdit;}
29 Fre: TCustomEdit;
30 FAutoLongLines: TNotifyEvent;
31 procedure InsertField;
32{ procedure Setre(const Value: TRichEdit);}
33 procedure Setre(const Value: TCustomEdit);
34 public
35 procedure UpdateStatus;
36{ property re: TRichEdit read Fre write Setre;}
37 property re: TCustomEdit read Fre write Setre;
38 property AutoLongLines: TNotifyEvent read FAutoLongLines write FAutoLongLines;
39 end;
40
41implementation
42
43uses
44 ORFn, rTemplates, uTemplateFields, fTemplateDialog, ORClasses;
45
46{$R *.DFM}
47
48procedure TfrmTemplateFields.FormShow(Sender: TObject);
49begin
50 cboObjects.SelectAll;
51 cboObjects.SetFocus;
52end;
53
54procedure TfrmTemplateFields.FormCreate(Sender: TObject);
55begin
56 cboObjects.InitLongList('');
57 cboObjects.ItemHeight := 15;
58 ResizeAnchoredFormToFont(self);
59 //ResizeAnchoredFormToFont doesn't work right on the button positions for some reason.
60 btnCancel.Left := pnlBottom.ClientWidth - btnCancel.Width;
61 btnInsert.Left := btnCancel.Left - btnInsert.Width - 8;
62end;
63
64procedure TfrmTemplateFields.cboObjectsNeedData(Sender: TObject;
65 const StartFrom: String; Direction, InsertAt: Integer);
66var
67 tmp: TStrings;
68
69begin
70 tmp := SubSetOfTemplateFields(StartFrom, Direction);
71 ConvertCodes2Text(tmp, FALSE);
72 cboObjects.ForDataUse(tmp);
73end;
74
75procedure TfrmTemplateFields.InsertField;
76var
77 cnt: integer;
78
79begin
80 if assigned(Fre) and (not TORExposedCustomEdit(Fre).ReadOnly) and (cboObjects.ItemIndex >= 0) then
81 begin
82 if Fre is TRichEdit then
83 cnt := TRichEdit(FRe).Lines.Count
84 else
85 cnt :=0;
86 Fre.SelText := TemplateFieldBeginSignature +
87 Piece(cboObjects.Items[cboObjects.ItemIndex],U,2)+
88 TemplateFieldEndSignature;
89 if Fre is TRichEdit then
90 if(assigned(FAutoLongLines) and (cnt <> TRichEdit(FRe).Lines.Count)) then
91 FAutoLongLines(Self);
92 end;
93end;
94
95procedure TfrmTemplateFields.cboObjectsDblClick(Sender: TObject);
96begin
97 if btnInsert.Enabled then
98 InsertField;
99end;
100
101procedure TfrmTemplateFields.btnCancelClick(Sender: TObject);
102begin
103 Close;
104end;
105
106procedure TfrmTemplateFields.FormClose(Sender: TObject;
107 var Action: TCloseAction);
108begin
109 Action := caHide;
110end;
111
112procedure TfrmTemplateFields.Setre(const Value: TCustomEdit);
113begin
114 Fre := Value;
115 UpdateStatus;
116end;
117
118procedure TfrmTemplateFields.UpdateStatus;
119begin
120 btnInsert.Enabled := (not TORExposedCustomEdit(re).ReadOnly);
121end;
122
123procedure TfrmTemplateFields.btnInsertClick(Sender: TObject);
124begin
125 InsertField;
126end;
127
128procedure TfrmTemplateFields.btnPreviewClick(Sender: TObject);
129var
130 tmp, txt: string;
131
132
133begin
134 if(cboObjects.ItemIndex >= 0) then
135 begin
136 FormStyle := fsNormal;
137 try
138 txt := Piece(cboObjects.Items[cboObjects.ItemIndex],U,2);
139 tmp := TemplateFieldBeginSignature + txt + TemplateFieldEndSignature;
140 CheckBoilerplate4Fields(tmp, 'Preview Template Field: ' + txt, TRUE);
141 finally
142 FormStyle := fsStayOnTop;
143 end;
144 end;
145end;
146
147procedure TfrmTemplateFields.cboObjectsChange(Sender: TObject);
148begin
149 btnPreview.Enabled := (cboObjects.ItemIndex >= 0)
150end;
151
152end.
Note: See TracBrowser for help on using the repository browser.