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