1 | unit FormColumns;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, VCard, FormEx;
|
---|
7 |
|
---|
8 | type
|
---|
9 |
|
---|
10 | { TFormColumns }
|
---|
11 |
|
---|
12 | TFormColumns = class(TFormEx)
|
---|
13 | ButtonUp: TButton;
|
---|
14 | ButtonToLeft: TButton;
|
---|
15 | ButtonCancel: TButton;
|
---|
16 | ButtonOk: TButton;
|
---|
17 | ButtonToRight: TButton;
|
---|
18 | ButtonDown: TButton;
|
---|
19 | Label1: TLabel;
|
---|
20 | Label2: TLabel;
|
---|
21 | ListBoxActive: TListBox;
|
---|
22 | ListBoxAvailable: TListBox;
|
---|
23 | procedure ButtonDownClick(Sender: TObject);
|
---|
24 | procedure ButtonOkClick(Sender: TObject);
|
---|
25 | procedure ButtonToLeftClick(Sender: TObject);
|
---|
26 | procedure ButtonToRightClick(Sender: TObject);
|
---|
27 | procedure ButtonUpClick(Sender: TObject);
|
---|
28 | procedure FormCreate(Sender: TObject);
|
---|
29 | procedure FormDestroy(Sender: TObject);
|
---|
30 | procedure FormShow(Sender: TObject);
|
---|
31 | procedure ListBoxActiveSelectionChange(Sender: TObject; User: boolean);
|
---|
32 | procedure ListBoxAvailableSelectionChange(Sender: TObject; User: boolean);
|
---|
33 | private
|
---|
34 | procedure SwapListItems(ListBox: TListBox; Index1, Index2: Integer);
|
---|
35 | public
|
---|
36 | ActiveColumns: TStringList;
|
---|
37 | AvailableColumns: TStringList;
|
---|
38 | procedure UpdateInterface;
|
---|
39 | end;
|
---|
40 |
|
---|
41 |
|
---|
42 | implementation
|
---|
43 |
|
---|
44 | {$R *.lfm}
|
---|
45 |
|
---|
46 | { TFormColumns }
|
---|
47 |
|
---|
48 | procedure TFormColumns.FormShow(Sender: TObject);
|
---|
49 | begin
|
---|
50 | ListBoxActive.Items.Assign(ActiveColumns);
|
---|
51 | ListBoxAvailable.Items.Assign(AvailableColumns);
|
---|
52 | ListBoxAvailable.Sorted := True;
|
---|
53 |
|
---|
54 | UpdateInterface;
|
---|
55 | end;
|
---|
56 |
|
---|
57 | procedure TFormColumns.ListBoxActiveSelectionChange(Sender: TObject;
|
---|
58 | User: boolean);
|
---|
59 | begin
|
---|
60 | UpdateInterface;
|
---|
61 | end;
|
---|
62 |
|
---|
63 | procedure TFormColumns.ListBoxAvailableSelectionChange(Sender: TObject;
|
---|
64 | User: boolean);
|
---|
65 | begin
|
---|
66 | UpdateInterface;
|
---|
67 | end;
|
---|
68 |
|
---|
69 | procedure TFormColumns.SwapListItems(ListBox: TListBox; Index1, Index2: Integer
|
---|
70 | );
|
---|
71 | var
|
---|
72 | Temp: string;
|
---|
73 | TempObject: TObject;
|
---|
74 | begin
|
---|
75 | Temp := ListBox.Items[Index1];
|
---|
76 | ListBox.Items[Index1] := ListBox.Items[Index2];
|
---|
77 | ListBox.Items[Index2] := Temp;
|
---|
78 | TempObject := ListBox.Items.Objects[Index1];
|
---|
79 | ListBox.Items.Objects[Index1] := ListBox.Items.Objects[Index2];
|
---|
80 | ListBox.Items.Objects[Index2] := TempObject;
|
---|
81 | end;
|
---|
82 |
|
---|
83 | procedure TFormColumns.ButtonUpClick(Sender: TObject);
|
---|
84 | begin
|
---|
85 | if ListBoxActive.ItemIndex > 0 then begin
|
---|
86 | SwapListItems(ListBoxActive, ListBoxActive.ItemIndex, ListBoxActive.ItemIndex - 1);
|
---|
87 | ListBoxActive.ItemIndex := ListBoxActive.ItemIndex - 1;
|
---|
88 | end;
|
---|
89 | end;
|
---|
90 |
|
---|
91 | procedure TFormColumns.ButtonDownClick(Sender: TObject);
|
---|
92 | begin
|
---|
93 | if ListBoxActive.ItemIndex < ListBoxActive.Items.Count - 1 then begin
|
---|
94 | SwapListItems(ListBoxActive, ListBoxActive.ItemIndex, ListBoxActive.ItemIndex + 1);
|
---|
95 | ListBoxActive.ItemIndex := ListBoxActive.ItemIndex + 1;
|
---|
96 | end;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | procedure TFormColumns.ButtonOkClick(Sender: TObject);
|
---|
100 | begin
|
---|
101 | ActiveColumns.Assign(ListBoxActive.Items);
|
---|
102 | end;
|
---|
103 |
|
---|
104 | procedure TFormColumns.ButtonToLeftClick(Sender: TObject);
|
---|
105 | begin
|
---|
106 | if ListBoxActive.ItemIndex = -1 then begin
|
---|
107 | ListBoxActive.Items.AddObject(ListBoxAvailable.Items[ListBoxAvailable.ItemIndex],
|
---|
108 | ListBoxAvailable.Items.Objects[ListBoxAvailable.ItemIndex])
|
---|
109 | end else begin
|
---|
110 | ListBoxActive.Items.InsertObject(ListBoxActive.ItemIndex,
|
---|
111 | ListBoxAvailable.Items[ListBoxAvailable.ItemIndex],
|
---|
112 | ListBoxAvailable.Items.Objects[ListBoxAvailable.ItemIndex]);
|
---|
113 | end;
|
---|
114 | ListBoxAvailable.Items.Delete(ListBoxAvailable.ItemIndex);
|
---|
115 | end;
|
---|
116 |
|
---|
117 | procedure TFormColumns.ButtonToRightClick(Sender: TObject);
|
---|
118 | begin
|
---|
119 | ListBoxAvailable.Items.AddObject(ListBoxActive.Items[ListBoxActive.ItemIndex],
|
---|
120 | ListBoxActive.Items.Objects[ListBoxActive.ItemIndex]);
|
---|
121 | ListBoxActive.Items.Delete(ListBoxActive.ItemIndex);
|
---|
122 | end;
|
---|
123 |
|
---|
124 | procedure TFormColumns.FormCreate(Sender: TObject);
|
---|
125 | begin
|
---|
126 | ActiveColumns := TStringList.Create;
|
---|
127 | AvailableColumns := TStringList.Create;
|
---|
128 | end;
|
---|
129 |
|
---|
130 | procedure TFormColumns.FormDestroy(Sender: TObject);
|
---|
131 | begin
|
---|
132 | FreeAndNil(ActiveColumns);
|
---|
133 | FreeAndNil(AvailableColumns);
|
---|
134 | end;
|
---|
135 |
|
---|
136 | procedure TFormColumns.UpdateInterface;
|
---|
137 | begin
|
---|
138 | ButtonToLeft.Enabled := ListBoxAvailable.ItemIndex <> -1;
|
---|
139 | ButtonToRight.Enabled := ListBoxActive.ItemIndex <> -1;
|
---|
140 | ButtonDown.Enabled := (ListBoxActive.ItemIndex <> -1) and (ListBoxActive.ItemIndex < ListBoxActive.Items.Count - 1);
|
---|
141 | ButtonUp.Enabled := (ListBoxActive.ItemIndex <> -1) and (ListBoxActive.ItemIndex > 0);
|
---|
142 | end;
|
---|
143 |
|
---|
144 | end.
|
---|
145 |
|
---|