1.安卓程序的退出询问和锁手机屏幕翻转
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.StdCtrls; type TForm1 = class(TForm) btn1: TButton; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure btn1Click(Sender: TObject); procedure FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.fmx} uses FMX.Platform.Android; {点击按钮退出} procedure TForm1.btn1Click(Sender: TObject); begin Close; end; {对话框的退出函数} procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin {退出程序} MainActivity.finish; end; {退出前询问} procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin if MessageDlg('是否退出?', TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbOK, TMsgDlgBtn.mbCancel], -1) = mrOK then CanClose := true else CanClose := false; end; {对话框创建} procedure TForm1.FormCreate(Sender: TObject); begin {锁定屏幕不翻转} Application.FormFactor.Orientations := [TFormOrientation.soLandscape, TFormOrientation.soInvertedLandscape]; end; {按下返回键} procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); begin {当按下硬件键盘的返回按钮时,关闭当前窗体} if Key = vkHardwareBack then Close; end; end.