[delphi] GetSystemInfo - 获取系统信息
一、声明
代码
1 GetSystemInfo(
2 var lpSystemInfo: TSystemInfo {}
3 );
4 //TSystemInfo 是 _SYSTEM_INFO 结构的重定义:
5 _SYSTEM_INFO = record
6 case Integer of
7 0: (
8 dwOemId: DWORD); {返回计算机标识符, 已废弃}
9 1: (
10 wProcessorArchitecture: Word; {处理器的体系结构}
11 wReserved: Word; {保留}
12 dwPageSize: DWORD; {分页大小}
13 lpMinimumApplicationAddress: Pointer;{最小寻址空间}
14 lpMaximumApplicationAddress: Pointer;{最大寻址空间}
15 dwActiveProcessorMask: DWORD; {处理器掩码; 0..31 表示不同的处理器}
16 dwNumberOfProcessors: DWORD; {处理器数目}
17 dwProcessorType: DWORD; {处理器类型}
18 dwAllocationGranularity: DWORD; {虚拟内存空间的粒度}
19 wProcessorLevel: Word; {处理器等级}
20 wProcessorRevision: Word); {处理器版本}
21 end;
22
2 var lpSystemInfo: TSystemInfo {}
3 );
4 //TSystemInfo 是 _SYSTEM_INFO 结构的重定义:
5 _SYSTEM_INFO = record
6 case Integer of
7 0: (
8 dwOemId: DWORD); {返回计算机标识符, 已废弃}
9 1: (
10 wProcessorArchitecture: Word; {处理器的体系结构}
11 wReserved: Word; {保留}
12 dwPageSize: DWORD; {分页大小}
13 lpMinimumApplicationAddress: Pointer;{最小寻址空间}
14 lpMaximumApplicationAddress: Pointer;{最大寻址空间}
15 dwActiveProcessorMask: DWORD; {处理器掩码; 0..31 表示不同的处理器}
16 dwNumberOfProcessors: DWORD; {处理器数目}
17 dwProcessorType: DWORD; {处理器类型}
18 dwAllocationGranularity: DWORD; {虚拟内存空间的粒度}
19 wProcessorLevel: Word; {处理器等级}
20 wProcessorRevision: Word); {处理器版本}
21 end;
22
二、例子
例子
1 unit Unit1;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, StdCtrls, ComCtrls;
8
9 type
10 TForm1 = class(TForm)
11 btn1: TButton;
12 redt1: TRichEdit;
13 procedure btn1Click(Sender: TObject);
14 private
15 { Private declarations }
16 public
17 { Public declarations }
18 end;
19
20 var
21 Form1: TForm1;
22
23 implementation
24
25 {$R *.dfm}
26
27 procedure TForm1.btn1Click(Sender: TObject);
28 var
29 sys:TSystemInfo;
30 begin
31 GetSystemInfo(sys);
32 with redt1.Lines do
33 begin
34 Add(Format('处理器类型 (ProcessorType):' + #9#9 +'%d',[sys.dwProcessorType]));
35 Add(Format('OEMID: ' +#9#9#9#9#9 + '%d',[sys.dwOemId]));
36 Add(Format('处理器架构 (ProcessorArchitecture):' + #9#9 + '%d',[sys.wProcessorArchitecture]));
37 Add(Format('处理器数量 (NumberOfProcessors):'+ #9#9 + '%d',[sys.dwNumberOfProcessors]));
38 Add(Format('处理器版本 (ProcessorRevision):' + #9#9 + '%d',[sys.wProcessorRevision]));
39 Add(Format('分页大小 (PageSize):' + #9#9#9 + '%d',[Sys.dwPageSize]));
40 Add(Format('最小寻址空间 (MinimumApplicationAddress):' +#9 + '%d',[Integer(Sys.lpMinimumApplicationAddress)]));
41 Add(Format('最大寻址空间 (MaximumApplicationAddress):' +#9 + '%d',[Integer(Sys.lpMaximumApplicationAddress)]));
42 Add(Format('处理器掩码 (ActiveProcessorMask):' +#9#9 + '%d',[Integer(Sys.dwActiveProcessorMask)]));
43 Add(Format('处理器内存粒度 (AllocationGranularity):' +#9 + '%d',[Integer(Sys.dwAllocationGranularity)]));
44 Add(Format('处理器等级 (ProcessorLevel):' +#9#9 + '%d',[Integer(Sys.wProcessorLevel)]));
45
46 end;
47
48
49 end;
50
51 end.
52
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, StdCtrls, ComCtrls;
8
9 type
10 TForm1 = class(TForm)
11 btn1: TButton;
12 redt1: TRichEdit;
13 procedure btn1Click(Sender: TObject);
14 private
15 { Private declarations }
16 public
17 { Public declarations }
18 end;
19
20 var
21 Form1: TForm1;
22
23 implementation
24
25 {$R *.dfm}
26
27 procedure TForm1.btn1Click(Sender: TObject);
28 var
29 sys:TSystemInfo;
30 begin
31 GetSystemInfo(sys);
32 with redt1.Lines do
33 begin
34 Add(Format('处理器类型 (ProcessorType):' + #9#9 +'%d',[sys.dwProcessorType]));
35 Add(Format('OEMID: ' +#9#9#9#9#9 + '%d',[sys.dwOemId]));
36 Add(Format('处理器架构 (ProcessorArchitecture):' + #9#9 + '%d',[sys.wProcessorArchitecture]));
37 Add(Format('处理器数量 (NumberOfProcessors):'+ #9#9 + '%d',[sys.dwNumberOfProcessors]));
38 Add(Format('处理器版本 (ProcessorRevision):' + #9#9 + '%d',[sys.wProcessorRevision]));
39 Add(Format('分页大小 (PageSize):' + #9#9#9 + '%d',[Sys.dwPageSize]));
40 Add(Format('最小寻址空间 (MinimumApplicationAddress):' +#9 + '%d',[Integer(Sys.lpMinimumApplicationAddress)]));
41 Add(Format('最大寻址空间 (MaximumApplicationAddress):' +#9 + '%d',[Integer(Sys.lpMaximumApplicationAddress)]));
42 Add(Format('处理器掩码 (ActiveProcessorMask):' +#9#9 + '%d',[Integer(Sys.dwActiveProcessorMask)]));
43 Add(Format('处理器内存粒度 (AllocationGranularity):' +#9 + '%d',[Integer(Sys.dwAllocationGranularity)]));
44 Add(Format('处理器等级 (ProcessorLevel):' +#9#9 + '%d',[Integer(Sys.wProcessorLevel)]));
45
46 end;
47
48
49 end;
50
51 end.
52
没事,别怕,这是签名→→┃ 青山幽谷笛声扬,白鹤振羽任翱翔。往事前尘随风逝,携手云峰隐仙乡。 ┃