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