DelphiDabbler Code Snippets Database

Snippet Selection

The following snippets from the Code Snippets Database have been requested.

GetTotalPhysMemory

Returns the total physical memory in bytes. Returns 0 on error. Use GetLastError to get the error code.

function GetTotalPhysMemory: Int64;
var
  MemoryEx: Windows.TMemoryStatusEx;
begin
  begin
    MemoryEx.dwLength := SizeOf(TMemoryStatusEx);
    Windows.GlobalMemoryStatusEx(MemoryEx);
    Result := MemoryEx.ullTotalPhys;
  end;
end;

TerminateProcessByID

Forcefully terminates the process with the given process ID. Returns True on success and False if the process ID is invalid or if the process can't be terminated.

function TerminateProcessByID(ProcessID: Cardinal): Boolean;
var
  HProcess : THandle;
begin
  Result := False;
  HProcess := Windows.OpenProcess(Windows.PROCESS_TERMINATE, False, ProcessID);
  if HProcess > 0 then
  try
    Result := SysUtils.Win32Check(Windows.TerminateProcess(HProcess, 0));
  finally
    Windows.CloseHandle(HProcess);
  end;
end;

View the whole database.

Go to the DelphiDabbler website.