unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// Memory Status
type
DWORDLONG = UInt64;
TMemoryStatusEx = record
dwLength: DWORD;
dwMemoryLoad: DWORD;
ullTotalPhys: DWORDLONG;
ullAvailPhys: DWORDLONG;
ullTotalPageFile: DWORDLONG;
ullAvailPageFile: DWORDLONG;
ullTotalVirtual: DWORDLONG;
ullAvailVirtual: DWORDLONG;
ullAvailExtendedVirtual: DWORDLONG;
end;
function GlobalMemoryStatusEx(var lpBuffer: TMEMORYSTATUSEX): BOOL; stdcall; external kernel32;
function MemoryStatus(var InUse: Integer; var PhysicalTotal, PhysicalFree,
VirtualTotal, VirtualFree, PagingTotal, PagingFree: UInt64): Boolean;
var Status: TMemoryStatusEx;
begin
Status.dwLength := SizeOf(Status);
Result := GlobalMemoryStatusEx(Status);
if Result then
begin
InUse := Status.dwMemoryLoad;
PhysicalTotal := Status.ullTotalPhys;
PhysicalFree := Status.ullAvailPhys;
VirtualTotal := Status.ullTotalVirtual;
VirtualFree := Status.ullAvailVirtual;//delphitop.com
PagingTotal := Status.ullTotalPageFile;
PagingFree := Status.ullAvailPageFile;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
const
MB = 1024 * 1024;
var
Text: string;
InUse: Integer;
PhysicalTotal, PhysicalFree: UInt64;
VirtualTotal, VirtualFree: UInt64;
PagingTotal, PagingFree: UInt64;
begin
if MemoryStatus(InUse, PhysicalTotal, PhysicalFree,
VirtualTotal, VirtualFree, PagingTotal, PagingFree) then
begin
Text := 'Memory in use: ' + IntToStr(InUse) + '%' + #13#10 +
'Total physical memory: ' + IntToStr(PhysicalTotal div MB) + ' MB' + #13#10 +
'Free physical memory: ' + IntToStr(PhysicalFree div MB) + ' MB' + #13#10 +
'Total virtual memory: ' + IntToStr(VirtualTotal div MB) + ' MB' + #13#10 +
'Free virtual memory: ' + IntToStr(VirtualFree div MB) + ' MB' + #13#10 +
'Total paging file: ' + IntToStr(PagingTotal div MB) + ' MB' + #13#10 +
'Free paging file: ' + IntToStr(PagingFree div MB) + ' MB';
Memo1.Clear;
Memo1.Lines.Add(Text);
end;
end;
end.