This repository has been archived by the owner on Jun 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
/
AreaTableUnit.pas
128 lines (111 loc) · 2.83 KB
/
AreaTableUnit.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
unit AreaTableUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Functions, ExtCtrls, JvExComCtrls, JvListView;
type
TAreaTableForm = class(TForm)
PageControl1: TPageControl;
tsSearch: TTabSheet;
pnSearch: TPanel;
edSearchMask: TLabeledEdit;
Panel1: TPanel;
btOK: TButton;
btCancel: TButton;
lvList: TListView;
procedure lvListChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
procedure edSearchMaskChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure lvListDblClick(Sender: TObject);
procedure lvListColumnClick(Sender: TObject; Column: TListColumn);
private
prmName, prmID: integer;
procedure Search();
public
procedure Prepare(Text: string);
function GetValue(ID: integer): WideString;
end;
var
AreaTableForm: TAreaTableForm;
implementation
uses MyDataModule, MainUnit;
{$R *.dfm}
{ TAreaTableForm }
procedure TAreaTableForm.Prepare(Text: string);
var
i: integer;
begin
if lvList.Items.Count=0 then SetList(lvList, 'AreaTable');
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 TAreaTableForm.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 TAreaTableForm.lvListChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
begin
btOK.Enabled:=Assigned(lvList.Selected);
end;
procedure TAreaTableForm.lvListColumnClick(Sender: TObject; Column: TListColumn);
begin
if column.Index = 0 then
begin
lvList.CustomSort(@CustomIDSortProc, prmID);
prmID := -prmID;
end
else
begin
lvList.CustomSort(@CustomNameSortProc, prmName);
prmName := -prmName;
end;
end;
procedure TAreaTableForm.lvListDblClick(Sender: TObject);
begin
if Assigned(TJvListView(Sender).Selected) then ModalResult:=mrOk;
end;
procedure TAreaTableForm.edSearchMaskChange(Sender: TObject);
begin
Search;
end;
procedure TAreaTableForm.FormCreate(Sender: TObject);
begin
if not MainForm.MyTrinityConnection.Connected then Exit;
dmMain.Translate.CreateDefaultTranslation(TForm(Self));
dmMain.Translate.TranslateForm(TForm(Self));
end;
function TAreaTableForm.GetValue(id: integer): WideString;
var
i: integer;
begin
Result:='';
if id<1 then Exit;
for i:=0 to lvList.Items.Count - 1 do
begin
if id = StrToIntDef(lvList.Items[i].Caption,0) then
begin
Result := lvList.Items[i].SubItems[0];
Exit;
end;
end;
end;
end.