1 | unit UFormCategorySelect;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
9 | UAcronym;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TFormCategorySelect }
|
---|
14 |
|
---|
15 | TFormCategorySelect = class(TForm)
|
---|
16 | ButtonOk: TButton;
|
---|
17 | ButtonCancel: TButton;
|
---|
18 | ListBox1: TListBox;
|
---|
19 | procedure FormShow(Sender: TObject);
|
---|
20 | procedure ListBox1DblClick(Sender: TObject);
|
---|
21 | procedure ListBox1KeyPress(Sender: TObject; var Key: char);
|
---|
22 | private
|
---|
23 | { private declarations }
|
---|
24 | public
|
---|
25 | procedure Load(RemoveItems: TStrings);
|
---|
26 | end;
|
---|
27 |
|
---|
28 | var
|
---|
29 | FormCategorySelect: TFormCategorySelect;
|
---|
30 |
|
---|
31 | resourcestring
|
---|
32 | SCategory = 'Category';
|
---|
33 | SRemoveCategory = 'Remove categories';
|
---|
34 | SRemoveCategoryQuery = 'Do you really want to remove selected categories?';
|
---|
35 |
|
---|
36 | implementation
|
---|
37 |
|
---|
38 | {$R *.lfm}
|
---|
39 |
|
---|
40 | uses
|
---|
41 | UFormMain;
|
---|
42 |
|
---|
43 | { TFormCategorySelect }
|
---|
44 |
|
---|
45 | procedure TFormCategorySelect.FormShow(Sender: TObject);
|
---|
46 | begin
|
---|
47 | end;
|
---|
48 |
|
---|
49 | procedure TFormCategorySelect.ListBox1DblClick(Sender: TObject);
|
---|
50 | begin
|
---|
51 | ButtonOk.Click;
|
---|
52 | end;
|
---|
53 |
|
---|
54 | procedure TFormCategorySelect.ListBox1KeyPress(Sender: TObject; var Key: char);
|
---|
55 | begin
|
---|
56 | if Key = #13 then ButtonOk.Click;
|
---|
57 | end;
|
---|
58 |
|
---|
59 | procedure TFormCategorySelect.Load(RemoveItems: TStrings);
|
---|
60 | var
|
---|
61 | Index: Integer;
|
---|
62 | I: Integer;
|
---|
63 | begin
|
---|
64 | with FormMain.AcronymDb do begin
|
---|
65 | ListBox1.Sorted := False;
|
---|
66 | while ListBox1.Items.Count < Categories.Count do
|
---|
67 | ListBox1.Items.Add('');
|
---|
68 | while ListBox1.Items.Count > Categories.Count do
|
---|
69 | ListBox1.Items.Delete(ListBox1.Items.Count - 1);
|
---|
70 | for I := 0 to Categories.Count - 1 do begin
|
---|
71 | ListBox1.Items.Strings[I] := TAcronymCategory(Categories[I]).Name;
|
---|
72 | ListBox1.Items.Objects[I] := Categories[I];
|
---|
73 | ListBox1.Selected[I] := False;
|
---|
74 | end;
|
---|
75 | ListBox1.Sorted := True;
|
---|
76 | for I := 0 to RemoveItems.Count - 1 do begin
|
---|
77 | Index := ListBox1.Items.IndexOf(RemoveItems[I]);
|
---|
78 | if Index <> -1 then ListBox1.Items.Delete(Index);
|
---|
79 | end;
|
---|
80 | end;
|
---|
81 | end;
|
---|
82 |
|
---|
83 | end.
|
---|
84 |
|
---|