Jump to content

pcplayer99

Members
  • Content Count

    93
  • Joined

  • Last visited

Posts posted by pcplayer99


  1. Thank you Lars.

     

    My Program is:

     

    1. Scan device. then list devices.

    2. Let user select a device, and user click a "Select" button.

    3. in the button onclick event handler, find the device, and set user selected device to FMyDevice, and then call BluetoothLE1.DiscoverServices(Self.FMyDevice);

    4. Do someting that need service, call GetService(FMyDevice), and then maybe ok, maybe got nil.


  2. Android, Delphi 10.3.3. community version.

     

    TBluetoothLE  scan BLE device ok, and then:

    var
      AService: TBluetoothGattService;

     

    AService := BluetoothLE1.GetService(Self.FMyDevice, Service_ID);
    if not Assigned(AService) then raise exception.Create('No service found.');

     

    Here, mybe I can got the service, mybe not, on the same device. Maybe I restart APP and can got service.


  3.   T := TMyThread.Create(True);

      T.Start;

     

    equal:

     

    T := TMyThread.Create;

     

    After  T := TMyThread.Create this thread run immediately.

     

    I write this:

      T := TMyThread.Create(True);

      T.Start;

     

    just want to place a break point here when thread was created and see what happend. And I have seen something: when there is a break point, and program stopped here, and then I press F8, and F8, it works fine. So I guess that maybe I can stop here for some while and I add a Sleep(500) here and it works fine.


  4. 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,
      FMX.Controls.Presentation;
    
    type
      TForm1 = class(TForm)
        ToolBar1: TToolBar;
        Button1: TSpeedButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        FNumb: Integer;
      public
        { Public declarations }
      end;
    
      TMyThread = class(TThread)
      private
        procedure aaaa;
      public
        procedure Execute; override;
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.fmx}
    
    { TMyThread }
    
    procedure TMyThread.aaaa;
    begin
    
      Form1.Button1.Text := 'aaa' + Form1.FNumb.ToString;
      Form1.Updated;
    
      Inc(Form1.FNumb);
    end;
    
    procedure TMyThread.Execute;
    begin
      inherited;
      Self.Synchronize(aaaa);
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      T: TMyThread;
    begin
    
      T := TMyThread.Create(True);
    
      T.Start;
    end;
    
    end.

     

     

    Above code can run OK under Windows, but in Android, it can not run into TMyThread.Execute;

     

    if Add a Sleep(500) as code below, it can run OK in Android:

     

    procedure TForm1.Button1Click(Sender: TObject);
    var
      T: TMyThread;
    begin
    
      T := TMyThread.Create(True);
      Sleep(500);
      T.Start;
    end;

     

    So, I guess in Android, var T is a local variable and after exit Button1Click method, it was released by ARC.

     

    So I move var T: TMyThread declare to global variable at var Form1: TForm, and then delete Sleep(500) and then tested in Android, it works OK.


  5.    PODBALMMSG2 = ^ODBALMMSG2;
    
       ODBALMMSG2 = packed record
          alm_no: LongInt;
          atype: SmallInt;
          axis: SmallInt;
          dummy: SmallInt;
          msg_len: SmallInt;
          alm_msg: array [0 .. 63] of AnsiChar;
       end;

     

     

    In Delphi,if you has code like this:

     

    procedure DoSometiing(xxxxx: xx);

    var

      MyR: ODBALMMSG2

    begin

       ////do something...

    end;

     

    Here, you got a record MyR, its memory is prepared statically. It is a instance, you can use it directly.  And the pointer of this instance is: @MyR.

     

    If you has code like this:

    procedure DoSometing(xxx: xxx);

    var

      MyR_P: PODBALMMSG2

    begin

       /// Here, MyR_P is a pointer that type is PODBALMMSG2 but it is a pointer, you can just use a normal pointer type instead PODBALMMSG2.

      /// Here, MyR_P is just a variable, there is no instance, no memory that store data. If you want use it, you must allocate memory for it. And, you must free the memory when you want to give up it.

       MyR_P := GetMem(SizeOf(ODBALMMSG2));

      try

         do something...

      finally

        FreeMem(MyR_P);

      end;

     

     

       /// or, you can use this function:

       New(MyR_P);

      try

        Do something....

     finally

      Dispose(MyR_P);

    end;

    end;

    • Thanks 1

  6. I did some research about this topic.

    It seems that we should use some "Headless Browser" with Python.

    But I try to use delphi.

     

    So, I have tested using outerHTML, innerHTML etc, and I have tested another way: Copy/Paste.

    And, I can got the HTML text but with some JS code or HTML tag. I can not get plain text that user can read at all.


  7. Just a test program, too simple:

      TForm1 = class(TForm)
        ToolBar1: TToolBar;
        SpeedButton1: TSpeedButton;
        MediaPlayer1: TMediaPlayer;
        MediaPlayerControl1: TMediaPlayerControl;
        Layout1: TLayout;
        ProgressBar1: TProgressBar;
        Timer1: TTimer;
        Layout2: TLayout;
        Label1: TLabel;
        procedure SpeedButton1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure FormShow(Sender: TObject);
      private
        { Private declarations }
        function GetMyFileName: string;
    
        procedure GetPermissions;
      public
        { Public declarations }
      end;

     

    There are some code copy from "RADStudio10.3Demos-master\Object Pascal\Mobile Snippets\VideoPlayback" :

     

    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      if ProgressBar1.Max <> MediaPlayer1.Duration then
        ProgressBar1.Max := MediaPlayer1.Duration;
      if ProgressBar1.Value <> MediaPlayer1.CurrentTime then
        ProgressBar1.Value := MediaPlayer1.CurrentTime;
    end;

     

    Compile IDE: Delphi 10.3.1 Community version.

     

    Test environment:

    A. Android 5.0;

    B. Android 9.0;

     

    Issues:

     

    1. If there is no MediaPlayerControl1, under Android 5.0 it can play MP4 video file, can hear  audio playing of this MP4 file, and ProgressBar1 working fine . But if there is a MediaPlayerControl1, after I call MediaPlayer1.Play, APP will raise a exception: Project testMediaPlayer.apk raised exception class EJNIException with message 'java.io.IOException: Prepare failed.: status=0x80000000'.

     

    2. Under Android 9.0, it can play MP4 video, but ProgressBar1 can not work. Set up a break-point on "if ProgressBar1.Max <> MediaPlayer1.Duration then"  every time the timer1 trigger,  MediaPlayer1.Duration is -1.


  8. Delphi 10.3.1

     

    My steps:

     

    1. BluetoothLE1.DiscoverDevices(3000);  Can find device, trigger BluetoothLE1EndDiscoverDevices event.

    2. FDevice.DiscoverServices; can get services. I can got a service by: AService := BluetoothLE1.GetService(FDevice, MyService_ID);

    3. and then if I call: ACharacteristic := BluetoothLE1.GetCharacteristic(AService, My_Characteristic_ID);  I got nil.

     

    -----------

    at 3, this method will be ok:

    for I := 0 to AService.Characteristics.Count -1 do
      begin
        if Aservice.Characteristics.UUID = My_Characteristic_ID then
        begin
          ACharacteristic := Aservice.Characteristics;
          Break;
        end;
      end;

     

    After I do this for loop, ACharacteristic := BluetoothLE1.GetCharacteristic(AService, My_Characteristic_ID); will get the right thing.

     

    So, Is it a issue?


  9. Maybe I know what issue it is. The reason is that server side use some .Net Object that Delphi can not handle.

     

    for a example:

    If I create SOAP server by Delphi, and I will create a client side by delphi, I can output TDataSetProvider from the server and my Delphi client can handle it but C# or Java can not. 

     

    Here maybe your server write by C# and it useing some Object just by C# ?


  10. The exception is clear: 

     SOAP classes must derive from TRemotable

    If you write SOAP code with using DELPHI, you must know, in SOAP interface methods, if the data type is a object, it must derive from TRemotable. If it is a TComponent, it can not using in SOAP method. Here I mean is that you design a SOAP server.

     

    If there is a running SOAP server, you can using  "Component/import WSDL" menu in Delphi IDE menu, and Delphi will create some SOAP client code for you.


  11. On Android 6, I can play MP4 by call TJIntent:

     

        uri := StrToJURI('file://' + AURI);
    
        Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW);
        intent.setDataAndType(uri, StringToJstring('video/mp4'));
        TAndroidHelper.Activity.startActivity(Intent); 

     

    On Android 9, there is a exception:

    raised exception class EJNIException with message 'android.os.FileUriExposedException: file:///storage/emulated/0/Download/VIDOES/4114049.mp4 exposed beyond app through Intent.getData()

     

    I have googled on Internet, it must use file provider. There is a demo code in:  https://community.idera.com/developer-tools/platforms/f/android-platform/68376/my-apps-autoupdate-not-working-rio-10-3-1-tokyo-10-2-3-working

     

    and in this link: https://www.delphiworlds.com/2018/06/targeting-android-8-and-higher-continued/  it is said that we need add some provider code into AndroidManifest.template.

     

    So, I write code like this:

     

    AJavaFile := TJFile.JavaClass.init(StringToJstring( AURI));
    uri := TAndroidHelper.JFileToJURI(AJavaFile);   

     

    and update AndroidManifest.template file add some code in it:

     

    <application android:persistent="%persistent%" 
            android:restoreAnyVersion="%restoreAnyVersion%" 
            android:label="%label%" 
            android:debuggable="%debuggable%" 
            android:largeHeap="%largeHeap%"
            android:icon="%icon%"
            android:theme="%theme%"
            android:hardwareAccelerated="%hardwareAccelerated%"
            android:resizeableActivity="false">
    
             <%provider%>
    		
    		<provider
              android:name="android.support.v4.content.FileProvider"
              android:authorities="com.embarcadero.firemonkey.fileprovider"
              android:exported="false"
              android:grantUriPermissions="true">
              <meta-data android:name="android.support.FILE_PROVIDER_PATHS" 
    		  android:resource="@xml/provider_paths"/>  
            </provider>   
    		
            <%application-meta-data%>
            <%services%>
            <!-- Our activity is a subclass of the built-in NativeActivity framework class.
                 This will take care of integrating with our NDK code. -->
            <activity android:name="com.embarcadero.firemonkey.FMXNativeActivity"
                    android:label="%activityLabel%"
                    android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
                    android:launchMode="singleTask">
                <!-- Tell NativeActivity the name of our .so -->
                <meta-data android:name="android.app.lib_name"
                    android:value="%libNameValue%" />
                <intent-filter>  
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter> 
            </activity>
            <%activity%>
            <%receivers%>
        </application>

     

    another XML file is provider_paths.xml, like this:

    <?xml version="1.0" encoding="utf-8"?>
    <paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
    </paths>

     

    but when call "uri := TAndroidHelper.JFileToJURI(AJavaFile); " there is a exception: 

    raised exception class EJNIException with message 'java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference'.

     

    So, is there a demo that how to call a TJIntent on Android 7 or higher version?

     

     


  12. I run test app on Android 9, under debug mode, step by step, press F7 when it stoped on this: PermissionsService.RequestPermissions([FLocationPermission], RequestPermissionsResult, DisplayRationale);

    But it can not go into the implementation code, it go into some ASM code in function _InstClear(var Dest: TObject): Pointer; in  system unit.

     

    In the same condition, if I press Ctr + Left click RequestPermissions, it go into:

     

    procedure TPermissionsService.RequestPermissions(const APermissions: TArray<string>;
      const AOnRequestPermissionsResult: TRequestPermissionsResultEvent; AOnDisplayRationale: TDisplayRationaleEvent);

     

    So, check this procedure in System.Permissions, there is no code to call AOnDisplayRationale.


  13. There is a demo named BLEScanner with Delphi.

    In this demo, you can find some code about permission:

    procedure TForm6.btnStartScanClick(Sender: TObject);
    begin
      PermissionsService.RequestPermissions([FLocationPermission], RequestPermissionsResult, DisplayRationale);
    end;
    
    procedure TForm6.DisplayRationale(Sender: TObject; const APermissions: TArray<string>; const APostRationaleProc: TProc);
    begin
      TDialogService.ShowMessage('We need to be given permission to discover BLE devices',
        procedure(const AResult: TModalResult)
        begin
          APostRationaleProc;
        end)
    end;
      
     procedure TForm6.RequestPermissionsResult(Sender: TObject; const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>);
    begin
      // 1 permissions involved: ACCESS_COARSE_LOCATION
      if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then
        StartBLEDiscovery
      else
        TDialogService.ShowMessage('Cannot start BLE scan as the permission has not been granted');
    end;

     

    But because the bug, DisplayRationale never be called.


  14. In Delphi rio 10.3 Comunity edition, permission framework is in System.Permissions.pas.

     

    But, there are some bugs ? There are two method that we can request permission to call it. But the parameter "AOnDisplayRationale" has never be used by these two methods.

     

    procedure TPermissionsService.RequestPermissions(const APermissions: TArray<string>;
      const AOnRequestPermissionsResult: TRequestPermissionsResultEvent; AOnDisplayRationale: TDisplayRationaleEvent);
    var
      GrantResults: TArray<TPermissionStatus>;
      I: Integer;
    begin
      SetLength(GrantResults, Length(APermissions));
      for I := Low(GrantResults) to High(GrantResults) do
        GrantResults[I] := TPermissionStatus.Granted;
      AOnRequestPermissionsResult(Self, APermissions, GrantResults)
    end;
    
    procedure TPermissionsService.RequestPermissions(const APermissions: TArray<string>;
      const AOnRequestPermissionsResult: TRequestPermissionsResultProc; AOnDisplayRationale: TDisplayRationaleProc);
    var
      GrantResults: TArray<TPermissionStatus>;
      I: Integer;
    begin
      SetLength(GrantResults, Length(APermissions));
      for I := Low(GrantResults) to High(GrantResults) do
        GrantResults[I] := TPermissionStatus.Granted;
      AOnRequestPermissionsResult(APermissions, GrantResults)
    end;

     


  15. 17 hours ago, azrael_11 said:

    Is DsPack support fmx native o have a popup window when play a video file?

     

    Dspack is a set of VCL control, so, you can use it to write a mediaplayer you self in VCL mode. And then, you can embed a VCL form into your FMX project.

    Dspack wrapped DirectShow9 as pascal code and you can use it in Delphi. The MediaPlayer in FMX under Windows is Windows mediaplayer that using DirectShow9 and wrapped by pascal. So, essentially these two is wrapped the same Windows component.

     

    By using Dspack, you have more degree of freedom, using TMediaPlayer by FMX, you have extremely few public method and property to use.

×