1 | unit FormDevices;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, ExtCtrls,
|
---|
7 | Machine;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormDevices }
|
---|
12 |
|
---|
13 | TFormDevices = class(TForm)
|
---|
14 | TreeView1: TTreeView;
|
---|
15 | procedure FormShow(Sender: TObject);
|
---|
16 | procedure TreeView1DblClick(Sender: TObject);
|
---|
17 | private
|
---|
18 |
|
---|
19 | public
|
---|
20 | Devices: TDevices;
|
---|
21 | procedure ReloadDevices;
|
---|
22 | end;
|
---|
23 |
|
---|
24 |
|
---|
25 | implementation
|
---|
26 |
|
---|
27 | {$R *.lfm}
|
---|
28 |
|
---|
29 | uses
|
---|
30 | FormConsole, FormScreen, FormStorage;
|
---|
31 |
|
---|
32 | const
|
---|
33 | DeviceClassFormClasses: array[TDeviceClass] of TFormDeviceClass = (
|
---|
34 | nil, nil, nil, TFormStorage, TFormScreen, TFormConsole, nil);
|
---|
35 |
|
---|
36 | { TFormDevices }
|
---|
37 |
|
---|
38 | procedure TFormDevices.FormShow(Sender: TObject);
|
---|
39 | begin
|
---|
40 | ReloadDevices;
|
---|
41 | end;
|
---|
42 |
|
---|
43 | procedure TFormDevices.TreeView1DblClick(Sender: TObject);
|
---|
44 | var
|
---|
45 | FormClass: TFormDeviceClass;
|
---|
46 | Device: TDevice;
|
---|
47 | begin
|
---|
48 | if Assigned(TreeView1.Selected) then begin
|
---|
49 | if Assigned(TreeView1.Selected.Data) and (TObject(TreeView1.Selected.Data) is TDevice) then begin
|
---|
50 | Device := TDevice(TreeView1.Selected.Data);
|
---|
51 | if not Assigned(Device.Form) then begin
|
---|
52 | FormClass := DeviceClassFormClasses[Device.DeviceClass];
|
---|
53 | if Assigned(FormClass) then begin
|
---|
54 | Device.Form := FormClass.Create(nil);
|
---|
55 | Device.Form.Device := Device;
|
---|
56 | Device.Form.Show;
|
---|
57 | end;
|
---|
58 | end
|
---|
59 | end;
|
---|
60 | end;
|
---|
61 | end;
|
---|
62 |
|
---|
63 | procedure TFormDevices.ReloadDevices;
|
---|
64 | var
|
---|
65 | I: Integer;
|
---|
66 | GroupNode: TTreeNode;
|
---|
67 | Node: TTreeNode;
|
---|
68 | DeviceClasses: TDeviceClassSet;
|
---|
69 | DeviceClass: TDeviceClass;
|
---|
70 | ClassDevices: TDevices;
|
---|
71 | begin
|
---|
72 | with TreeView1 do
|
---|
73 | try
|
---|
74 | BeginUpdate;
|
---|
75 | Items.Clear;
|
---|
76 | Items.AddChild(nil, 'Devices');
|
---|
77 | DeviceClasses := Devices.GetClasses;
|
---|
78 | for DeviceClass := Low(TDeviceClass) to High(TDeviceClass) do
|
---|
79 | if DeviceClass in DeviceClasses then begin
|
---|
80 | GroupNode := Items.AddChild(TopItem, DeviceClassText[DeviceClass]);
|
---|
81 | ClassDevices := Devices.GetDevicesByClass(DeviceClass);
|
---|
82 | for I := 0 to ClassDevices.Count - 1 do begin
|
---|
83 | Node := Items.AddChild(GroupNode, ClassDevices[I].Name);
|
---|
84 | Node.Data := ClassDevices[I];
|
---|
85 | end;
|
---|
86 | ClassDevices.Free;
|
---|
87 | end;
|
---|
88 | TopItem.Expand(True);
|
---|
89 | finally
|
---|
90 | EndUpdate;
|
---|
91 | end;
|
---|
92 | end;
|
---|
93 |
|
---|
94 | end.
|
---|
95 |
|
---|