| 1 | unit fTemplateObjects; | 
|---|
| 2 |  | 
|---|
| 3 | interface | 
|---|
| 4 |  | 
|---|
| 5 | uses | 
|---|
| 6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, | 
|---|
| 7 | ORCtrls, StdCtrls, ExtCtrls, ComCtrls, ORFn, dShared; | 
|---|
| 8 |  | 
|---|
| 9 | type | 
|---|
| 10 | TfrmTemplateObjects = class(TForm) | 
|---|
| 11 | cboObjects: TORComboBox; | 
|---|
| 12 | pnlBottom: TPanel; | 
|---|
| 13 | btnCancel: TButton; | 
|---|
| 14 | btnInsert: TButton; | 
|---|
| 15 | btnRefresh: TButton; | 
|---|
| 16 | procedure FormShow(Sender: TObject); | 
|---|
| 17 | procedure btnInsertClick(Sender: TObject); | 
|---|
| 18 | procedure cboObjectsDblClick(Sender: TObject); | 
|---|
| 19 | procedure btnCancelClick(Sender: TObject); | 
|---|
| 20 | procedure btnRefreshClick(Sender: TObject); | 
|---|
| 21 | procedure FormClose(Sender: TObject; var Action: TCloseAction); | 
|---|
| 22 | private | 
|---|
| 23 | Fre: TRichEdit; | 
|---|
| 24 | FAutoLongLines: TNotifyEvent; | 
|---|
| 25 | procedure InsertObject; | 
|---|
| 26 | procedure Setre(const Value: TRichEdit); | 
|---|
| 27 | public | 
|---|
| 28 | procedure UpdateStatus; | 
|---|
| 29 | property re: TRichEdit read Fre write Setre; | 
|---|
| 30 | property AutoLongLines: TNotifyEvent read FAutoLongLines write FAutoLongLines; | 
|---|
| 31 | end; | 
|---|
| 32 |  | 
|---|
| 33 | implementation | 
|---|
| 34 |  | 
|---|
| 35 | {$R *.DFM} | 
|---|
| 36 |  | 
|---|
| 37 | procedure TfrmTemplateObjects.FormShow(Sender: TObject); | 
|---|
| 38 | begin | 
|---|
| 39 | ResizeAnchoredFormToFont(self); | 
|---|
| 40 | //ResizeAnchoredFormToFont doesn't work right on the button positions for some reason. | 
|---|
| 41 | btnCancel.Left := pnlBottom.ClientWidth - btnCancel.Width; | 
|---|
| 42 | btnInsert.Left := btnCancel.Left - btnInsert.Width - 5; | 
|---|
| 43 | btnRefresh.Left := btnInsert.Left - btnRefresh.Width - 5; | 
|---|
| 44 | cboObjects.SelectAll; | 
|---|
| 45 | cboObjects.SetFocus; | 
|---|
| 46 | end; | 
|---|
| 47 |  | 
|---|
| 48 | procedure TfrmTemplateObjects.btnInsertClick(Sender: TObject); | 
|---|
| 49 | begin | 
|---|
| 50 | InsertObject; | 
|---|
| 51 | end; | 
|---|
| 52 |  | 
|---|
| 53 | procedure TfrmTemplateObjects.InsertObject; | 
|---|
| 54 | var | 
|---|
| 55 | cnt: integer; | 
|---|
| 56 |  | 
|---|
| 57 | begin | 
|---|
| 58 | if(not Fre.ReadOnly) and (cboObjects.ItemIndex >= 0) then | 
|---|
| 59 | begin | 
|---|
| 60 | cnt := Fre.Lines.Count; | 
|---|
| 61 | Fre.SelText := '|'+Piece(cboObjects.Items[cboObjects.ItemIndex],U,3)+'|'; | 
|---|
| 62 | if(assigned(FAutoLongLines) and (cnt <> FRe.Lines.Count)) then | 
|---|
| 63 | FAutoLongLines(Self); | 
|---|
| 64 | end; | 
|---|
| 65 | end; | 
|---|
| 66 |  | 
|---|
| 67 | procedure TfrmTemplateObjects.cboObjectsDblClick(Sender: TObject); | 
|---|
| 68 | begin | 
|---|
| 69 | InsertObject; | 
|---|
| 70 | end; | 
|---|
| 71 |  | 
|---|
| 72 | procedure TfrmTemplateObjects.btnCancelClick(Sender: TObject); | 
|---|
| 73 | begin | 
|---|
| 74 | Close; | 
|---|
| 75 | end; | 
|---|
| 76 |  | 
|---|
| 77 | procedure TfrmTemplateObjects.FormClose(Sender: TObject; | 
|---|
| 78 | var Action: TCloseAction); | 
|---|
| 79 | begin | 
|---|
| 80 | Action := caHide; | 
|---|
| 81 | end; | 
|---|
| 82 |  | 
|---|
| 83 | procedure TfrmTemplateObjects.Setre(const Value: TRichEdit); | 
|---|
| 84 | begin | 
|---|
| 85 | Fre := Value; | 
|---|
| 86 | UpdateStatus; | 
|---|
| 87 | end; | 
|---|
| 88 |  | 
|---|
| 89 | procedure TfrmTemplateObjects.UpdateStatus; | 
|---|
| 90 | begin | 
|---|
| 91 | btnInsert.Enabled := (not re.ReadOnly); | 
|---|
| 92 | end; | 
|---|
| 93 |  | 
|---|
| 94 | procedure TfrmTemplateObjects.btnRefreshClick(Sender: TObject); | 
|---|
| 95 | begin | 
|---|
| 96 | cboObjects.SelectAll; | 
|---|
| 97 | cboObjects.Clear; | 
|---|
| 98 | dmodShared.RefreshObject := true; | 
|---|
| 99 | dmodShared.LoadTIUObjects; | 
|---|
| 100 | CboOBJECTS.Items.AddStrings(dmodShared.TIUObjects); | 
|---|
| 101 | end; | 
|---|
| 102 |  | 
|---|
| 103 | end. | 
|---|