VCL.Sensors Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to use different sensor components such as: TLocationSensor, TMotionSensor or TOrientationSensor.

Location

You can find the Sensors sample project at:

  • Start | Programs | Embarcadero RAD Studio Alexandria | Samples and then navigate to:
    • Object Pascal\VCL\Sensors
    • CPP\VCL\Sensors
  • Subversion Repository:
    • You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Description

The Sensors sample demonstrates how to use sensor components on a VCL application. The sample uses TLocationSensor, TMotionSensor and TOrientationSensor to provide related sensor information.

How to Use the Sample

  1. Navigate to one of the locations given above and open:
    • Delphi: VCLSensors.dproj.
    • C++: VCLSensorsCpp.cbproj.
  2. Press F9 or choose Run > Run.

Files

File in Delphi File in C++ Contains

VCLSensors.dproj
VCLSensors.dpr

VCLSensorsCpp.cbproj
VCLSensorsCpp.cpp

The project itself.

uMain.pas
uMain.fmx

uMain.h
uMain.cpp
uMain.fmx

The main form.

Classes

TForm5 is the main form that represents the main window of the sample. It contains the following components:

  • A TGroupBox object, named GroupBox4, that contains:
  • A TLocationSensor object named lsLocation.
  • A TMotionSensor object named msAccelerometer.
  • Two TOrientationSensor objects, named osCompass and osInclinometer.
  • A TPanel object, named Panel1, that contains tree TGroupBox objects.
    • GroupObject1 contains tree TLabel objects, named lAddress, lCoordinates and lGeoCoordinates.
    • GroupObject2 contains a TLabel object named lAccel.
    • GroupObject3 contains two TLabel objects, named lCompass and lInclinometer.
  • Two TTimer objects, named tMotion and tOrientation.

Implementation

  • The sample uses TLocationSensor to determine the location information of the device.
  • The sample uses TMotionSensor to offer information about the acceleration in each coordinate axis.
  • The sample uses TOrientationSensor to give information about the device inclination and compass heading.
  • The sample uses TButton to enable the VCL sensors.
  • The sample uses TTimer to repeat specific actions after a given time interval. Each TTimer specifies the time interval in which each sensor offers information to the user.
  • The sample uses TLabel to display text on the form. Each label is used to display each sensor information.
  • The sample uses TGroupBox to group related controls on a form. In this sample, each TGroupBox groups the labels that display information about the sample sensor.

When you run the application, the Active properties of the VCL sensors are set to False, which means that all the sensors are disabled. Moreover, you see the form divided in four TGroupBox objects with the following captions: Location, Motion, Orientation and Manage. The GroupBox4, labeled as Manage, contains the bSwitch button with its caption displaying the text Turn on. When you click on the bSwitch button, its caption changes to Turn off and the Active property of the VCL sensors changes to True. Then, the information related with each sensor is displayed using the labels that contain each TGroupBox object.

Uses

See Also

Samples