-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathuTree.pas
More file actions
133 lines (112 loc) · 3.04 KB
/
uTree.pas
File metadata and controls
133 lines (112 loc) · 3.04 KB
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
129
130
131
132
133
unit Utree;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, DB, Data.FMTBcd, Data.SqlExpr, FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt,
FireDAC.Comp.DataSet, FireDAC.Comp.Client;
type
TTreeForm = class(TForm)
FDQuery1: TFDQuery;
TreeView1: TTreeView;
ListView1: TListView;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure TreeView1Click(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
MyRec = record
Code:string;
Dept:string;
end;
Prt_MyRec = ^MyRec;
var
TreeForm: TTreeForm;
implementation
uses udm;
var
Wk_Dept:string;
p:Prt_MyRec;
OldWidth, OldHeight : integer;
{$R *.dfm}
procedure TTreeForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
j:byte;
begin
for j := 0 to Treeview1.Items.Count - 1 do
if TreeView1.Items[j].Data <> nil then
Dispose(Prt_MyRec(TreeView1.Items[j].Data));
Action := caFree;
end;
procedure TTreeForm.FormCreate(Sender: TObject);
begin
OldHeight := Height;
OldWidth := Width;
FDQuery1.Open;
with FDQuery1, Treeview1 do
Begin
while Not Eof do
Begin
if Wk_Dept <> FieldByName('Dept').asString then
Begin
Selected :=
Items.Add(Selected,FieldByName('Dept').asString);
Wk_Dept := FieldByName('Dept').asString;
End;
New(p);
p^.Code := FieldByName('Code').asString;
Items.AddChildobject(Selected,FieldByName('section').asString,p);
// items.AddChild(selected,FieldByName('section').asstring);
Next;
End;
End;
end;
procedure TTreeForm.FormResize(Sender: TObject);
var
t,px,py : real ;
i : byte ;
begin
px := OldWidth / Width;
py := OldHeight / Height;
for i := 0 to Componentcount -1 do
if Components[i] is TControl then
begin
t := (Components[i] as TControl).Left;
(Components[i] as TControl).Left := Trunc(t/px);
t := (Components[i] as TControl).Top;
(Components[i] as TControl).Top := Trunc(t/py);
t := (Components[i] as TControl).Width;
(Components[i] as TControl).Width := Trunc(t/px);
t := (Components[i] as TControl).Height;
(Components[i] as TControl).Height := Trunc(t/py);
end;
OldWidth := Width ;
OldHeight := Height;
end;
procedure TTreeForm.TreeView1Click(Sender: TObject);
var
ListItem:TListitem;
begin
if not Treeview1.Selected.HasChildren then
Begin
DM.InsaQuery.Close;
DM.InsaQuery.Params[0].AsString :=
Prt_MyRec(TreeView1.Selected.Data)^.Code;
DM.InsaQuery.Open;
ListView1.Clear;
while not DM.InsaQuery.Eof do
Begin
ListItem := ListView1.Items.Add;
ListItem.Caption :=
DM.InsaQuery.Fieldbyname('Name').asString;
ListItem.SubItems.Add(DM.InsaQuery.Fieldbyname('class').asstring);
DM.InsaQuery.Next;
End;
End;
end;
end.