forked from Ravie/quice
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ListUnit.pas
112 lines (95 loc) · 2.44 KB
/
ListUnit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
unit ListUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls, JvExComCtrls, JvListView;
type
TListForm = class(TForm)
Panel1: TPanel;
btOK: TButton;
btCancel: TButton;
pnSearch: TPanel;
edSearchMask: TLabeledEdit;
lvList: TListView;
procedure lvList2Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
procedure edSearchMaskChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure lvList2DblClick(Sender: TObject);
procedure lvListColumnClick(Sender: TObject; Column: TListColumn);
private
prmID: integer;
procedure Search();
public
procedure Prepare(Text: string);
end;
var
ListForm: TListForm;
implementation
uses MyDataModule, Functions;
{$R *.dfm}
{ TListForm }
procedure TListForm.Prepare(Text: string);
var
i: integer;
begin
if Trim(Text)='' then Exit;
for i:=0 to lvList.Items.Count - 1 do
begin
if lvList.Items[i].Caption = Text then
begin
lvList.Selected:=lvList.Items[i];
lvList.Selected.MakeVisible(false);
Exit;
end;
end;
end;
procedure TListForm.Search;
var
i: integer;
begin
for i:=0 to lvList.Items.Count - 1 do
begin
if Pos(LowerCase(edSearchMask.Text), LowerCase(lvList.Items[i].SubItems[0])) > 0 then
begin
lvList.Selected:=lvList.Items[i];
lvList.Selected.MakeVisible(false);
Exit;
end;
end;
end;
procedure TListForm.lvList2Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
begin
btOK.Enabled:=Assigned(lvList.Selected);
end;
procedure TListForm.lvList2DblClick(Sender: TObject);
begin
if Assigned(TJvListView(Sender).Selected) then ModalResult:=mrOk;
end;
procedure TListForm.lvListColumnClick(Sender: TObject; Column: TListColumn);
begin
if column.Index = 0 then
begin
lvList.CustomSort(@CustomIDSortProc, prmID);
prmID := -prmID;
end
else
lvList.CustomSort(@CustomNameSortProc, column.Index);
end;
procedure TListForm.edSearchMaskChange(Sender: TObject);
begin
Search;
end;
procedure TListForm.FormCreate(Sender: TObject);
begin
prmID := 1;
dmMain.Translate.CreateDefaultTranslation(TForm(Self));
dmMain.Translate.TranslateForm(TForm(Self));
end;
procedure TListForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if key = vk_escape then Close;
end;
end.