source: branches/CpuSingleSize/Forms/FormDevices.pas

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