source: tags/1.1.0/Forms/UFormImportFormat.pas

Last change on this file was 31, checked in by chronos, 8 years ago
  • Added: Import format for MS Access database.
  • Added: Show text hints on toolbar buttons.
File size: 5.3 KB
Line 
1unit UFormImportFormat;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
9 ComCtrls, Menus, ActnList, UAcronym;
10
11type
12
13 { TFormImportFormat }
14
15 TFormImportFormat = class(TForm)
16 AAdd: TAction;
17 AMoveUp: TAction;
18 AMoveDown: TAction;
19 AModify: TAction;
20 ARemove: TAction;
21 ActionList1: TActionList;
22 ButtonOk: TButton;
23 ButtonCancel: TButton;
24 ComboBoxType: TComboBox;
25 EditBlockEnd: TEdit;
26 EditBlockStart: TEdit;
27 EditName: TEdit;
28 Label1: TLabel;
29 Label2: TLabel;
30 Label3: TLabel;
31 Label8: TLabel;
32 Label9: TLabel;
33 ListViewItemRules: TListView;
34 MenuItem1: TMenuItem;
35 MenuItem2: TMenuItem;
36 MenuItem3: TMenuItem;
37 MenuItem4: TMenuItem;
38 MenuItem5: TMenuItem;
39 PopupMenu1: TPopupMenu;
40 procedure AAddExecute(Sender: TObject);
41 procedure AModifyExecute(Sender: TObject);
42 procedure AMoveDownExecute(Sender: TObject);
43 procedure AMoveUpExecute(Sender: TObject);
44 procedure ARemoveExecute(Sender: TObject);
45 procedure FormCreate(Sender: TObject);
46 procedure FormShow(Sender: TObject);
47 procedure ListViewItemRulesData(Sender: TObject; Item: TListItem);
48 private
49 { private declarations }
50 public
51 ImportFormat: TImportFormat;
52 procedure Load(ImportFormat: TImportFormat);
53 procedure Save(ImportFormat: TImportFormat);
54 procedure ReloadList;
55 end;
56
57var
58 FormImportFormat: TFormImportFormat;
59 YesNoString: array[Boolean] of string;
60
61
62implementation
63
64uses
65 UFormImportPattern;
66
67{$R *.lfm}
68
69resourcestring
70 SRemoveImportPattern = 'Remove import pattern';
71 SRemoveImportPatternQuery = 'Do you really want to remove selected import patterns?';
72 SYes = 'Yes';
73 SNo = 'No';
74
75
76{ TFormImportFormat }
77
78procedure TFormImportFormat.AAddExecute(Sender: TObject);
79var
80 NewImportPattern: TImportPattern;
81begin
82 NewImportPattern := TImportPattern.Create;
83 FormImportPattern.Load(NewImportPattern);
84 if FormImportPattern.ShowModal = mrOk then begin
85 FormImportPattern.Save(NewImportPattern);
86 ImportFormat.ItemPatterns.Add(NewImportPattern);
87 NewImportPattern := nil;
88 ReloadList;
89 end;
90 if Assigned(NewImportPattern) then NewImportPattern.Free;
91end;
92
93procedure TFormImportFormat.AModifyExecute(Sender: TObject);
94var
95 NewImportPattern: TImportPattern;
96begin
97 if Assigned(ListViewItemRules.Selected) then begin
98 NewImportPattern := TImportPattern.Create;
99 NewImportPattern.Assign(ListViewItemRules.Selected.Data);
100 FormImportPattern.Load(NewImportPattern);
101 if FormImportPattern.ShowModal = mrOk then begin
102 FormImportPattern.Save(NewImportPattern);
103 TImportPattern(ListViewItemRules.Selected.Data).Assign(NewImportPattern);
104 ReloadList;
105 end;
106 if Assigned(NewImportPattern) then NewImportPattern.Free;
107 end;
108end;
109
110procedure TFormImportFormat.AMoveDownExecute(Sender: TObject);
111begin
112 if ListViewItemRules.Selected.Index < (ImportFormat.ItemPatterns.Count - 1) then
113 with ImportFormat do
114 ItemPatterns.Exchange(ListViewItemRules.Selected.Index,
115 ListViewItemRules.Selected.Index + 1);
116 ReloadList;
117end;
118
119procedure TFormImportFormat.AMoveUpExecute(Sender: TObject);
120begin
121 if ListViewItemRules.Selected.Index > 0 then
122 with ImportFormat do
123 ItemPatterns.Exchange(ListViewItemRules.Selected.Index,
124 ListViewItemRules.Selected.Index - 1);
125 ReloadList;
126end;
127
128procedure TFormImportFormat.ARemoveExecute(Sender: TObject);
129var
130 I: Integer;
131begin
132 if Assigned(ListViewItemRules.Selected) then begin
133 if MessageDlg(SRemoveImportPattern, SRemoveImportPatternQuery,
134 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
135 for I := ListViewItemRules.Items.Count - 1 downto 0 do
136 if ListViewItemRules.Items[I].Selected then
137 ImportFormat.ItemPatterns.Remove(ListViewItemRules.Items[I].Data);
138 ReloadList;
139 end;
140 end;
141end;
142
143procedure TFormImportFormat.FormCreate(Sender: TObject);
144begin
145 YesNoString[False] := SNo;
146 YesNoString[True] := SYes;
147end;
148
149procedure TFormImportFormat.FormShow(Sender: TObject);
150begin
151 ReloadList;
152end;
153
154procedure TFormImportFormat.ListViewItemRulesData(Sender: TObject;
155 Item: TListItem);
156begin
157 if Item.Index < ImportFormat.ItemPatterns.Count then
158 with TImportPattern(ImportFormat.ItemPatterns[Item.Index]) do begin
159 Item.Caption := StartString;
160 Item.SubItems.Add(EndString);
161 Item.SubItems.Add(ImportPatternFlagString[Flag]);
162 Item.SubItems.Add(ImportVariableString[Variable]);
163 Item.SubItems.Add(YesNoString[Repetition]);
164 Item.Data := ImportFormat.ItemPatterns[Item.Index];
165 end;
166end;
167
168procedure TFormImportFormat.Load(ImportFormat: TImportFormat);
169begin
170 ComboBoxType.ItemIndex := Integer(ImportFormat.Kind);
171 Self.ImportFormat := ImportFormat;
172 EditName.Text := ImportFormat.Name;
173 EditBlockStart.Text := ImportFormat.Block.StartString;
174 EditBlockEnd.Text := ImportFormat.Block.EndString;
175 ReloadList;
176end;
177
178procedure TFormImportFormat.Save(ImportFormat: TImportFormat);
179begin
180 ImportFormat.Kind := TImportFormatKind(ComboBoxType.ItemIndex);
181 ImportFormat.Name := EditName.Text;
182 ImportFormat.Block.StartString := EditBlockStart.Text;
183 ImportFormat.Block.EndString := EditBlockEnd.Text;
184end;
185
186procedure TFormImportFormat.ReloadList;
187begin
188 ListViewItemRules.Items.Count := ImportFormat.ItemPatterns.Count;
189 ListViewItemRules.Refresh;
190end;
191
192end.
193
Note: See TracBrowser for help on using the repository browser.