本文整理自网络,侵删。
当TOrientationSensor组件的Active属性设置为True时,将获取信息。
OrientationSensor1.Active := True;在OnSensorChoosing事件中,指定要使用的传感器。
以下代码检查并选择可以获取设备倾斜度的传感器。
procedure TForm1.OrientationSensor1SensorChoosing(Sender: TObject; const Sensors: TSensorArray; var ChoseSensorIndex: Integer);var I: Integer;begin for I := 0 to High(Sensors) do begin if TCustomOrientationSensor.TProperty.TiltX in TCustomOrientationSensor(Sensors[I]).AvailableProperties then begin ChoseSensorIndex := I; Exit; end; end; ChoseSensorIndex := 0;end;以下代码检查并选择可以获取指南针航向的传感器。
procedure TForm1.OrientationSensor2SensorChoosing(Sender: TObject; const Sensors: TSensorArray; var ChoseSensorIndex: Integer);var I: Integer;begin for I := 0 to High(Sensors) do begin if TCustomOrientationSensor.TProperty.HeadingX in TCustomOrientationSensor(Sensors[I]).AvailableProperties then begin ChoseSensorIndex := I; Exit; end; end; ChoseSensorIndex := 0;end;在OnDataChanged事件中,获取传感器信息。
以下代码显示设备倾斜度。
procedure TForm1.OrientationSensor1DataChanged(Sender: TObject);begin LabelTiltX.Text := FloatToStr(OrientationSensor1.Sensor.TiltX); LabelTiltY.Text := FloatToStr(OrientationSensor1.Sensor.TiltY); LabelTiltZ.Text := FloatToStr(OrientationSensor1.Sensor.TiltZ);end;以下代码显示指南针的方向。
procedure TForm1.OrientationSensor2DataChanged(Sender: TObject);begin LabelHeadingX.Text := FloatToStr(OrientationSensor2.Sensor.HeadingX); LabelHeadingY.Text := FloatToStr(OrientationSensor2.Sensor.HeadingY); LabelHeadingZ.Text := FloatToStr(OrientationSensor2.Sensor.HeadingZ);end; 相关阅读 >>
Delphi getdrivetypea() 查看驱动器类型
Delphi 从 twebbrowser中获得当前输入处的链接
Delphi分别连接ms sqlserver、oracle和access数据库的连接字符串
更多相关阅读请进入《Delphi》频道 >>