How do I get battery info in Delphi
To get battery information in Delphi, you can use the TBattery class from the System.Win.Battery unit of the Delphi RTL. This class provides properties and methods that allow you to access various details about the battery installed on your computer, such as the battery level, charging state, and remaining time.
Here is an example of how you can use the TBattery class in Delphi to get battery information
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
uses System.SysUtils, System.Win.Battery; var Battery TBattery; begin Battery = TBattery.Create; try Get the battery level Writeln(‘Battery Level ‘, Battery.Level, ‘%’); Check if the battery is charging if Battery.Charging then Writeln(‘Battery is charging’) else Writeln(‘Battery is not charging’); Get the remaining battery time Writeln(‘Remaining Time ‘, Battery.RemainingTime.Hours, ‘h ‘, Battery.RemainingTime.Minutes, ‘m’); finally Battery.Free; end; end. |
This code sample uses the TBattery class to get the battery level, charging state, and remaining time. You can use the other properties and methods of this class to access other battery information, such as the battery capacity, temperature, and power state. For more information, please refer to the Delphi documentation and the TBattery class reference.
Leave a Reply