Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[navy][i]// for automatic syntax highlighting see faq102-6487
[/i][/navy][b]uses[/b]
Windows;
[b]type[/b]
TMemoryStatusEx = [b]record[/b]
dwLength: DWORD;
dwMemoryLoad: DWORD;
ullTotalPhys: Int64;
ullAvailPhys: Int64;
ullTotalPageFile: Int64;
ullAvailPageFile: Int64;
ullTotalVirtual: Int64;
ullAvailVirtual: Int64;
ullAvailExtendedVirtual: Int64;
[b]end[/b];
[b]function[/b] GetGlobalMemoryRecord: TMemoryStatusEx;
[b]type[/b]
TGlobalMemoryStatusEx = [b]procedure[/b]([b]var[/b] lpBuffer: TMemoryStatusEx); [b]stdcall[/b];
[b]var[/b]
ms : TMemoryStatus;
h : THandle;
gms : TGlobalMemoryStatusEx;
[b]begin[/b]
Result.dwLength := SizeOf(Result);
h := LoadLibrary(kernel32);
[b]try[/b]
[b]if[/b] h <> [purple]0[/purple] [b]then[/b]
[b]begin[/b]
@gms := GetProcAddress(h, [teal]'GlobalMemoryStatusEx'[/teal]);
[b]if[/b] @gms <> [b]nil[/b] [b]then[/b]
gms(Result)
[b]else[/b]
[b]begin[/b]
ms.dwLength := SizeOf(ms);
GlobalMemoryStatus(ms);
Result.dwMemoryLoad := ms.dwMemoryLoad;
Result.ullTotalPhys := ms.dwTotalPhys;
Result.ullAvailPhys := ms.dwAvailPhys;
Result.ullTotalPageFile := ms.dwTotalPageFile;
Result.ullAvailPageFile := ms.dwAvailPageFile;
Result.ullTotalVirtual := ms.dwTotalVirtual;
Result.ullAvailVirtual := ms.dwAvailVirtual;
[b]end[/b]
[b]end[/b];
[b]finally[/b]
FreeLibrary(h);
[b]end[/b];
[b]end[/b];
[b]function[/b] GetTotalRAM: Int64;
[b]begin[/b]
Result := GetGlobalMemoryRecord.ullTotalPhys;
[b]end[/b];
[navy][i]{$SetPEFlags $0020} { /LargeAddressAware }[/i][/navy]
[navy][i]{ This function returns a formatted string with at the appropriate level of bytes, kilobytes, megabytes, gigabytes, etc }[/i][/navy]
[b]function[/b] FormatBytes(ABytes: Int64; AShortRounding: Boolean = True): String;
[b]const[/b]
suffix : [b]array[/b][[purple]0..6[/purple]] [b]of[/b] String = ([teal]'B'[/teal], [teal]'KB'[/teal], [teal]'MB'[/teal], [teal]'GB'[/teal], [teal]'TB'[/teal], [teal]'PB'[/teal], [teal]'EB'[/teal]);
[b]var[/b]
l : Integer;
f : Double;
[b]begin[/b]
l := [purple]0[/purple];
f := ABytes;
[b]while[/b] (l < High(suffix)) [b]and[/b] (f >= [purple]1024[/purple]) [b]do[/b]
[b]begin[/b]
inc(l);
f := f / [purple]1024[/purple];
[b]end[/b];
[b]if[/b] AShortRounding [b]and[/b] (l < High(suffix)) [b]and[/b] (f >= [purple]1000[/purple]) [b]then[/b]
[b]begin[/b] [navy][i]// ensures eg. 1022 MB will show 0.99 GB
[/i][/navy] inc(l);
f := f / [purple]1024[/purple];
[b]end[/b];
Result := Format([teal]'%f %s'[/teal], [f, suffix[l]]);
[b]end[/b];