source: trunk/Forms/FormColumns.pas

Last change on this file was 162, checked in by chronos, 17 months ago
  • Modified: Updated Common package.
File size: 4.1 KB
Line 
1unit FormColumns;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, VCard, FormEx;
7
8type
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
42implementation
43
44{$R *.lfm}
45
46{ TFormColumns }
47
48procedure TFormColumns.FormShow(Sender: TObject);
49begin
50 ListBoxActive.Items.Assign(ActiveColumns);
51 ListBoxAvailable.Items.Assign(AvailableColumns);
52 ListBoxAvailable.Sorted := True;
53
54 UpdateInterface;
55end;
56
57procedure TFormColumns.ListBoxActiveSelectionChange(Sender: TObject;
58 User: boolean);
59begin
60 UpdateInterface;
61end;
62
63procedure TFormColumns.ListBoxAvailableSelectionChange(Sender: TObject;
64 User: boolean);
65begin
66 UpdateInterface;
67end;
68
69procedure TFormColumns.SwapListItems(ListBox: TListBox; Index1, Index2: Integer
70 );
71var
72 Temp: string;
73 TempObject: TObject;
74begin
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;
81end;
82
83procedure TFormColumns.ButtonUpClick(Sender: TObject);
84begin
85 if ListBoxActive.ItemIndex > 0 then begin
86 SwapListItems(ListBoxActive, ListBoxActive.ItemIndex, ListBoxActive.ItemIndex - 1);
87 ListBoxActive.ItemIndex := ListBoxActive.ItemIndex - 1;
88 end;
89end;
90
91procedure TFormColumns.ButtonDownClick(Sender: TObject);
92begin
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;
97end;
98
99procedure TFormColumns.ButtonOkClick(Sender: TObject);
100begin
101 ActiveColumns.Assign(ListBoxActive.Items);
102end;
103
104procedure TFormColumns.ButtonToLeftClick(Sender: TObject);
105begin
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);
115end;
116
117procedure TFormColumns.ButtonToRightClick(Sender: TObject);
118begin
119 ListBoxAvailable.Items.AddObject(ListBoxActive.Items[ListBoxActive.ItemIndex],
120 ListBoxActive.Items.Objects[ListBoxActive.ItemIndex]);
121 ListBoxActive.Items.Delete(ListBoxActive.ItemIndex);
122end;
123
124procedure TFormColumns.FormCreate(Sender: TObject);
125begin
126 ActiveColumns := TStringList.Create;
127 AvailableColumns := TStringList.Create;
128end;
129
130procedure TFormColumns.FormDestroy(Sender: TObject);
131begin
132 FreeAndNil(ActiveColumns);
133 FreeAndNil(AvailableColumns);
134end;
135
136procedure TFormColumns.UpdateInterface;
137begin
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);
142end;
143
144end.
145
Note: See TracBrowser for help on using the repository browser.