source: branches/simple/Forms/FormDevices.pas

Last change on this file was 42, checked in by chronos, 15 months ago
  • Modified: Improved simple virtual machine.
File size: 2.1 KB
Line 
1unit FormDevices;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, ExtCtrls,
7 Machine, Device;
8
9type
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
23implementation
24
25{$R *.lfm}
26
27uses
28 FormConsole, FormScreen, FormStorage, FormDevice;
29
30const
31 DeviceClassFormClasses: array[TDeviceClass] of TFormDeviceClass = (
32 nil, nil, nil, TFormStorage, TFormScreen, TFormConsole, nil);
33
34{ TFormDevices }
35
36procedure TFormDevices.FormShow(Sender: TObject);
37begin
38 ReloadDevices;
39end;
40
41procedure TFormDevices.TreeView1DblClick(Sender: TObject);
42var
43 FormClass: TFormDeviceClass;
44 Device: TDevice;
45begin
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;
59end;
60
61procedure TFormDevices.ReloadDevices;
62var
63 I: Integer;
64 GroupNode: TTreeNode;
65 Node: TTreeNode;
66 DeviceClasses: TDeviceClassSet;
67 DeviceClass: TDeviceClass;
68 ClassDevices: TDevices;
69begin
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;
90end;
91
92end.
93
Note: See TracBrowser for help on using the repository browser.