
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Media,
FMX.Controls.Presentation, FMX.StdCtrls;
type
TForm1 = class(TForm)
CameraComponent1: TCameraComponent;//闪光灯的控制控件
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID}
procedure TForm1.Button1Click(Sender: TObject);
begin
if Button1.Text = '开' then
begin
CameraComponent1.TorchMode := TTorchMode.tmModeOn;//开灯
Button1.Text := '关';
end
else
begin
CameraComponent1.TorchMode := TTorchMode.tmModeOff;//关灯
Button1.Text := '开';
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Enabled := CameraComponent1.HasFlash;//如果没有闪光灯,则按钮不起作用
CameraComponent1.Active := True;
end;
end.