[fpc-pascal] demonstration of bug which do not allow javavcl users to call Android API functions

Mgr. Janusz Chmiel janusz.chmiel at volny.cz
Thu Apr 18 15:01:48 CEST 2019


Here is little example, which indicates why is it not possible to call 
Android API functions while using Java FVCL bundle

unit MainForm;
{$mode objfpc}
{$H+}
interface
uses _System, Classes, Controls, Dialogs, Forms, GenChars, LCLIntf, 
Menus, StdCtrls, SysUtils, androidr22;
type
TFormMain = class(TForm)
PlayButton: TButton;
protected
procedure ButtonClick(A: TObject);
public

constructor Create(A: TComponent); override;

end;
var
FormMain: TFormMain;
jMediaPlayer1 : AOVibrator;
;
implementation


constructor TFormMain.Create(A: TComponent);

begin

inherited;

Caption := Application.Title;
PlayButton:= TButton.Create(Self);
PlayButton.Align := alTop;
PlayButton.Parent := Self;
PlayButton.Caption := 'Play live stream';
PlayButton.OnClick := @ButtonClick;
(*
*)
(*
*)
end;
procedure TFormMain.ButtonClick(A: TObject);
begin
if A = PlayButton then begin

jMediaPlayer1.vibrate(300);
end;
end;

end.

If you will compile this project and if you customize lovecalc project 
so this mainform.pas will be usable for you, you would get run-time 
error after running it on real Android device.
May be, that aactivity.pas which is The part of Pandroid bundle would 
solve this problem, but sure, whole Pascal project would had to be coded 
by using Mainactivity and not only Pascal form mode.




More information about the fpc-pascal mailing list