System info

How can I get and display the system free memory (like user free percent or GDI free percent)?
LVL 1
logosapienceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MadshiCommented:
That's kind o difficult. This "GetFreeSystemResources" API is only available in the 16 bit "user.exe", so you'll need to use thunking...   :-(

Regards, Madshi.
0
logosapienceAuthor Commented:
How can I do to use it?
0
F31203Commented:
Here is another solution :

unit form_check_mem;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Timer1: TTimer;
    Label5: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  tmpavl, tmptot, tmp90 : integer;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var memory : TMEMORYSTATUS;

begin
memory.dwLength := sizeof(memory);
GlobalMemoryStatus(memory);
tmpavl := memory.dwAvailPhys;
tmpavl := round(tmpavl / 1024);
label1.caption := 'AvailPhys    ' + inttostr(tmpavl);

tmptot := memory.dwTotalPhys;
tmptot := round(tmptot / 1024);
label3.caption := 'Total Mem.   '+inttostr(tmptot);
tmp90 := round((tmptot * 90) / 100);
label4.caption := inttostr(tmp90);
label5.caption := inttostr(round((memory.dwTotalPageFile/1024) - (memory.dwAvailPhys/1024)));

end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin

if tmp90 > tmpavl then Label1.Font.Color := clgreen else
    label1.font.color := clred;
Button1Click(self);

end;

end.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

MadshiCommented:
That's not what logosapience wanted...   :-)

Look at "Control Panel -> system", last tab. These system resources are what was asked. There's no 32bit API to ask this value.
0
intheCommented:
Hi
As madshi said the proposed answer is not what was asked for.
here is example of thunking to get the User,System and Gdi Free Resources note that this only works on win9* machines:


unit Thunker;

interface

const
  SYSres    = 0;
  USERres   = 2;
  GDIres    = 1;

function GetSystemResources(Res: Word): Word;
function UserPercentage : Integer;
function SystemPercentage : Integer;
function GDIPercentage : Integer;
procedure DisplayFreeResources;


implementation

uses Windows,SysUtils,Dialogs;

function ThunkLoadLibrary(LibraryName: PChar): THandle; stdcall; external kernel32 index 35;
procedure ThunkFreeLibrary(HInstance: THandle); stdcall; external kernel32 index 36;
function ThunkGetProcAddress(Hinstance: THandle; ProcName: PChar): Pointer; stdcall; external kernel32 index 37;
procedure Thunk; cdecl; external kernel32 name 'QT_Thunk';

{$StackFrames On}

var
  Th : THandle = 0;
  P: Pointer = nil;

function GetSystemResources(Res: Word): Word;
var
  Ar : array[0..$40] of Word;
begin
  Ar[0] := Th; //get major error without this ?
  Th := ThunkLoadLibrary('user.exe');
  if Th < 32 then
    raise Exception.Create('Error loading User.exe');
   ThunkFreeLibrary(Th);
  P := ThunkGetProcAddress(Th,'GetFreeSystemResources');
  if P = nil then
    raise Exception.Create('GetSystemResources function not found');
   asm
    push Res
    mov edx, P
    call Thunk
    mov Result, ax
  end;
end;

function UserPercentage : Integer;
 begin
  Result := GetSystemResources(USERres);
 end;

function SystemPercentage : Integer;
 begin
  Result := GetSystemResources(SYSres);
 end;

function GDIPercentage : Integer;
 begin
  Result := GetSystemResources(GDIres);
 end;

Procedure DisplayFreeResources;
begin
showmessage(
'SYSTEM : '+inttostr(SystemPercentage)+'%'+#13#10+
'USER : '+inttostr(UserPercentage)+'%'+#13#10+
'GDI : '+inttostr(GDIPercentage)+'%');
end;

end.



example of use :

add to uses section "Thunker" then on a button click or something do:

procedure TForm1.Button1Click(Sender: TObject);
begin
DisplayFreeResources;
end;

Regards Barry
0
logosapienceAuthor Commented:
OK thanks, it works well!
0
MadshiCommented:
logosapience, which solution are you using now?
0
logosapienceAuthor Commented:
Oh oh, Inthe, I accepted the wrong answer... how ca I do to give you the points?
0
MadshiCommented:
The only thing you can do is to write to the customer service. They have their own forum on the homepage of EE.
0
F31203Commented:
Do you want I introduce something like 'points for Inthe' to give him the points ?

Regards,

Pas
0
logosapienceAuthor Commented:
If you want, that would be the solution... Sorry for the mistake...

LogoS
0
logosapienceAuthor Commented:
No, that's not the solution because you will loose your question points  instead of your expert points... I'll ask the EE forum to solve this...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.