TCustomLightSensor is a class in the System.Sensors unit of the Delphi Standard Library that provides a base class for implementing a custom light sensor in a Delphi program. The TCustomLightSensor class is part of the System.Sensors.Components unit, which provides a set of components for accessing various types of sensors on a device, such as the light sensor, accelerometer, and GPS.
Here is an example of how you can use TCustomLightSensor in Delphi
First, include the System.Sensors and System.Sensors.Components units in your code by adding the following lines at the top of your program;
1 2 3 |
uses System.Sensors, System.Sensors.Components; |
Declare a variable of type TCustomLightSensor
1 2 |
var LightSensor: TCustomLightSensor; |
Create an instance of TCustomLightSensor
1 |
LightSensor := TCustomLightSensor.Create(nil); |
Enable the light sensor
1 |
LightSensor.Active := True; |
Read the light level from the sensor
1 2 3 4 5 6 |
var LightLevel: Single; begin LightLevel := LightSensor.Sensor.LightLevel; //Do something with the light level end; |
Disable the light sensor when you are done
1 |
LightSensor.Active := False; |
Finally, free the light sensor when it is no longer needed
1 |
LightSensor.Free; |
Keep in mind that the TCustomLightSensor class is just a base class for implementing a custom light sensor. It does not provide any functionality for accessing the light sensor on a device. To access the light sensor on a device, you will need to use platform-specific APIs, such as the Android Sensor APIs or the iOS Core Motion framework.
You can find more information about TCustomLightSensor in the Delphi documentation.
Leave a Reply