// // 退出... procedure TForm1.CornerButton2Click(Sender: TObject); begin if not assigned(intent) then FreeAndNil(intent); halt; end;
// // 调用Google服务,生成二维码... procedure TForm1.CornerButton3Click(Sender: TObject); var url: string; stream: TMemoryStream; ok: boolean; begin // // 远程Google服务的URL生成... url:=TIdURI.URLEncode('http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=L|0&chl='+memo2.Lines.Text); // // 调用Google服务,得到二维码... Stream:=TMemoryStream.Create; http.HTTPOptions:=[hoKeepOrigProtocol]; http.Request.Connection:='Keep-Alive'; try http.Get(url,stream); ok:=(Stream.Size>0); except ok:=false; end; http.Disconnect; // // 成功,显示二维码图片... if ok then begin image1.MultiResBitmap.Clear; Stream.Position:=0; with image1.MultiResBitmap.Add do begin bitmap.LoadFromStream(Stream); Scale:=FWinService.GetWindowScale(Self); end; end // // 失败、提示... else showmessage('生成二维码失败!'); FreeAndNil(Stream); end;
// // 清除... procedure TForm1.CornerButton4Click(Sender: TObject); begin memo1.Lines.Clear; end;
// // 开始扫描... procedure TForm1.CornerButton5Click(Sender: TObject); begin if assigned(ClipService) then begin clipservice.SetClipboard(''); // // 运行ZXing扫描程序 if not assigned(intent) then intent := tjintent.Create; intent.setAction(stringtojstring('com.google.zxing.client.android.SCAN')); intent.putExtra(tjintent.JavaClass.EXTRA_TEXT,stringtojstring('"SCAN_MODE", "CODE_39"')); sharedactivity.startActivityForResult(intent,0); // // 启动定时器... TimeCount := 0; timer1.Enabled := true; end else ShowMessage('不支持粘贴板,无法扫描!'); end;
// // 程序启动时,初始化粘贴板对象... procedure TForm1.FormCreate(Sender: TObject); begin intent:=nil; if not TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService,IInterface(ClipService)) then ClipService:=nil; end;
// // 监视粘贴板并取结果... procedure TForm1.Timer1Timer(Sender: TObject); begin // // 还未有结果,计时... if ClipService.GetClipboard.ToString='' then begin inc(TimeCount); if TimeCount>9 then begin timer1.Enabled := false; TimeCount := 0; end; exit; end; // // 已有结果,读结果... timer1.Enabled := false; TimeCount := 0; Memo1.Lines.text:=ClipService.GetClipboard.ToString; ClipService.SetClipboard(''); end;