source: branches/ByteArray/Forms/FormStorage.pas

Last change on this file was 5, checked in by chronos, 3 months ago
File size: 1.5 KB
Line 
1unit FormStorage;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, Storage,
7 Device;
8
9type
10
11 { TFormStorage }
12
13 TFormStorage = class(TFormDevice)
14 ListView1: TListView;
15 procedure FormShow(Sender: TObject);
16 procedure ListView1Data(Sender: TObject; Item: TListItem);
17 protected
18 function GetDevice: TDevice; override;
19 procedure SetDevice(AValue: TDevice); override;
20 public
21 Storage: TStorage;
22 procedure Reload;
23 end;
24
25
26implementation
27
28{$R *.lfm}
29
30const
31 ItemsPerLine = 16;
32
33{ TFormStorage }
34
35procedure TFormStorage.ListView1Data(Sender: TObject; Item: TListItem);
36var
37 Line: string;
38 I: Integer;
39 Text: string;
40 One: Byte;
41begin
42 if Item.Index < Storage.Size div ItemsPerLine then begin
43 Line := '';
44 Text := '';
45 for I := 0 to ItemsPerLine - 1 do begin
46 One := Storage.ReadByte(Item.Index * ItemsPerLine + I);
47 Line := Line + IntToHex(One, 2) + ' ';
48 if One >= 32 then Text := Text + Char(One)
49 else Text := Text + ' ';
50 end;
51 Item.Caption := IntToHex(Item.Index * ItemsPerLine, 8);
52 Item.SubItems.Add(Line);
53 Item.SubItems.Add(Text);
54 end;
55end;
56
57procedure TFormStorage.FormShow(Sender: TObject);
58begin
59 Reload;
60end;
61
62function TFormStorage.GetDevice: TDevice;
63begin
64 Result := Storage;
65end;
66
67procedure TFormStorage.SetDevice(AValue: TDevice);
68begin
69 if AValue is TStorage then
70 Storage := TStorage(AValue);
71end;
72
73procedure TFormStorage.Reload;
74begin
75 ListView1.Items.Count := Storage.Size div ItemsPerLine;
76 ListView1.Refresh;
77end;
78
79end.
80
Note: See TracBrowser for help on using the repository browser.