![Demo10APMFImage | Embarcadero RAD Studio Delphi C++Builder Blogs demo10apmfimage](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/01/Demo10APMFImage-7050796.jpg?resize=1140%2C694&ssl=1)
Sometimes Developers may need to perform implementations based on Machine’s Battery and CPU power status. How to collect such information’s quickly ? Don’t know how to do. Don’t worry. MiTec’s System Information Management Suite’s component helps to retrieve such information faster. In this blog post we will learn how to use the TMiTec_APM component to collect power status of your machine with the sample application.
Platforms: Windows.
Installation Steps:
You can easily install this Component Suite from GetIt Package Manager. The steps are as follows.
- Navigate In RAD Studio IDE->Tools->GetIt Package Manager->select Components in Categories->Components->Trail -MiTec system Information Component Suite 14.3 and click Install Button.
- Read the license and Click Agree All. An Information dialog saying ‘Requires a restart of RAD studio at the end of the process. Do you want to proceed? click yes and continue.
- It will download the plugin and installs it. Once installed Click Restart now.
How to run the Demo app:
- Navigate to the System Information Management Suite trails setup, Demos folder which is installed during Get It installation e.g) C:UsersDocumentsEmbarcaderoStudio21.0CatalogRepositoryMiTeC-14.3DemosDelphi10
- Open the APM project in RAD studio 10.4.1 compile and Run the application.
- This Demo App shows how to access the system information like Battery and CPU Power Status.
Components used in MSIC APM Demo App:
![APMProperties7451327 | Embarcadero RAD Studio Delphi C++Builder Blogs apmproperties 7451327](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/01/APMProperties-7451327.png?resize=305%2C363&ssl=1)
- TMiTeC_APM: Component to retrieve Machines AC, Processor and Battery Power Status information’s by its properties such as ACPowerStatus, Battery by Battery Index, ProcessorPowerStatus by CPU index.
- TTabSheet1 shows the list of AC power status and the selected battery status properties and TTabSheet2 shows the Processor power status properties.
Implementation Details:
- An instance is created APM of TMiTeC_APM. Using APM properties Machine AC Power status, Battery related properties such as Manufacturers, Charge status, Battery Life, etc. were added to the TabSheet1 UI components.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
procedure TwndMain.cbBatChange(Sender: TObject); var s: string; begin eBat.Text:=''; eBatCap.Text:=''; eBatRemain.Text:=''; eBatRate.Text:=''; eBatLife.Text:=''; pbBat.Position:=0; if cbBat.ItemIndex=-1 then Exit; with APM.Battery[cbBat.ItemIndex] do begin if APM.BatteryChargeStatus<>[bsNoBattery] then begin s:=''; if PowerState and BATTERY_CHARGING=BATTERY_CHARGING then s:=s+'charging, '; if PowerState and BATTERY_CRITICAL=BATTERY_CRITICAL then s:=s+'critical, '; if PowerState and BATTERY_DISCHARGING=BATTERY_DISCHARGING then s:=s+'discharging, '; if PowerState and BATTERY_POWER_ON_LINE=BATTERY_POWER_ON_LINE then s:=s+'power on-line, '; SetLength(s,Length(s)-2); eBat.Text:=s; eBatMan.Text:=Manufacturer; eBatChem.Text:=Chemistry; eBatID.Text:=UniqueID; eBatLife.Text:=FormatSeconds(EstimatedTime); if Capacity<>BATTERY_UNKNOWN_CAPACITY then eBatCap.Text:=Format('%d Wh',[Capacity div 1000]) else eBatCap.Text:='?'; if Voltage<>BATTERY_UNKNOWN_VOLTAGE then eBatVolt.Text:=Format('%d V',[Voltage div 1000]) else eBatVolt.Text:='?'; if CurrentCapacity<>BATTERY_UNKNOWN_CAPACITY then eBatRemain.Text:=Format('%d Wh',[CurrentCapacity div 1000]) else eBatRemain.Text:='?'; if Rate<>BATTERY_UNKNOWN_RATE then eBatRate.Text:=Format('%d W',[Rate div 1000]) else eBatRate.Text:='?'; pbBat.Max:=Capacity; pbBat.Position:=CurrentCapacity; cbBat.Hint:=SymbolicLink; end else eBat.Text:='No battery present'; end; end; |
- Using APM.ProcessorPowerStatus property provides information such as Max Frequency, Current Frequency, Frequency Limit, etc. for the selected CPU index and were added to the TabSheet2 UI components.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
procedure TwndMain.cbCPUChange(Sender: TObject); begin if cbCPU.ItemIndex=-1 then Exit; with APM.ProcessorPowerStatus[cbCPU.ItemIndex] do begin eMaxFreq.Text:=Format('%d MHz',[MaxMHz]); eFreq.Text:=Format('%d MHz',[CurrentMHz]); eFreqLimit.Text:=Format('%d MHz',[MHzLimit]); eMaxIdle.Text:=Format('%d',[MaxIdleState]); eIdle.Text:=Format('%d',[CurrentIdleState]); if MaxMHz>pbCPU.Max then pbCPU.Max:=MaxMHz; pbCPU.Position:=CurrentMHz; end; end; |
![APMDemo2152820 | Embarcadero RAD Studio Delphi C++Builder Blogs apmdemo 2152820](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/01/APMDemo-2152820.png?resize=750%2C406&ssl=1)
It’s that simple to collect the Machines Power status information for your application. Use this MiTeC component suite and get the job done quickly.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition