How can I use TOrientationSensor in Delphi?

TOrientationSensor is a component in the FireMonkey library in Delphi that allows you to detect and respond to changes in device orientation. It is similar to the TMotionSensor component, but it is specifically designed for handling orientation changes.

To use the TOrientationSensor component in Delphi, you will first need to add the FMX.Sensors unit to your uses clause. Then, you can drop a TOrientationSensor component onto your form and configure its properties, such as the interval at which it should update. Finally, you can handle the OnSensorChange event to respond to changes in device orientation.

Here is an example of using a TOrientationSensor component in Delphi:

This code will activate the orientation sensor when the form is created, and then updates the label with the new orientation values in Roll, Pitch and Yaw each time the sensor is changed.

You can also use the Interval property to specify the interval at which the sensor should update. And like the TMotionSensor, you can use the IsSensorSupported method before using a Orientation sensor.

It’s worth noting that not all devices have all the types of sensors, so you should check the IsSensorSupported method before using the Orientation sensor.

And you can use the OnActivate / OnDeactivate events to know when the sensor is available or not.

In summary, the TOrientationSensor component in Delphi allows you to easily detect and respond to changes in device orientation. You can use the properties and events of the component to configure and handle the sensor.


Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *