Jump to content

ertank

Members
  • Content Count

    233
  • Joined

  • Last visited

Posts posted by ertank


  1. Hello,

     

    I am using Delphi 10.3.3 to build an Android 32Bit app running on embedded device with Android 5.1.1 installed. Device has 32Bit CPU and I cannot try to see if building my app for 64Bit helps.

     

    There are several operations that app doing in a thread which total takes 6-10 seconds on average. In order to keep user patient, I put a label on screen showing operation is advancing step by step. That label is updated from inside a thread. Thread is started using "TThread.CreateAnonymousThread(<relevant procedure calling code here>).Start()" and Label update code is something as following:

    TThread.Synchronize(nil, procedure begin StatusUpdateLabel.Text := '1/' + MaxSteps.ToString(); StatusUpdateLabel.Repaint(); end);

    My initial code did not have that "StatusUpdateLabel.Repaint();" part in above code. Once I started to have that problem, I just try to see if it helps. My case it did not help at all. Label is placed on a TFrame and aligned to Top. Font Family is Default, Size is set to 30, Style is set to Bold.

     

    Following is a video I try to put together for better understanding. Try to watch it at full screen. That video displays problem only for 1/9 at the beginning. Problem I am having is with number 1 in that video. That exact problem maybe on number 9, or both 1 and 9 numbers and it maybe in a total different step of the operation. It may happen more than once, too. Interestingly forward slash never has a problem at all. Moreover, I do not always have that problem. It sometimes displays everything as it should be.

     

    My guess, depending on internet speed some steps are completed fast. Sometimes pretty fast. When that happens, I get a very tiny text displayed on that Label. I did not have a chance to try reproducing that on a regular mobile phone. Once I find time, I am going to do that for sure.

     

    I wonder if that is some kind of a known problem and if there is a way to fix it.

     

    Thanks & regards,

    Ertan


  2. 4 minutes ago, David Heffernan said:

    I haven't got time to look at this but my guess is that you need to be overriding CreateWindowHandle and DestroyWindowHandle instead of CreateWnd and DestroyWnd. 

     

    CreateWindowHandle and DestroyWindowHandle are the methods tasked with he actual creation and destruction of the window. 

    That did solve my problem.


  3. Hello,

     

    I have found that stackoverflow code of @David Heffernan

    https://stackoverflow.com/questions/4354071/how-can-i-allow-a-form-to-accept-file-dropping-without-handling-windows-messages

     

    Attached is a project where I put it all together for my use case. However, it seems to leak some memory. I do not know why but TForm2.DestroyWnd seems not executed at all.

     

    I simply run and close the application without doing anything. Below dialog is my leak report message

    image.png.ce63add6fed053ac3e1ebe603fe1fe80.png

     

    Any help is appreciated.

     

    Thanks & regards,

    Ertan

    DragDrop.7z


  4. On 11/14/2019 at 6:51 PM, Fr0sT.Brutal said:

    What if CallStuffThatMightBlockForever never returns?

    Maybe you can run two threads?

    Something like your thread-1 does the loop. Upon a variable trigger or a procedure call, thread-1 runs the possibly never ending code in thread-2.

    After that thread-1 checks if that thread-2 terminates in a given time limits.

    If there is a timeout, your main app can provide a feedback to user and maybe an option to re-start the app or something.


  5. I started an Android project and did not give its package name a proper name. Now project is almost finished and remember to provide it a proper package name before releasing.

     

    - I changed the package name.

    - I removed installed app on my test phone.

    - Restarted the phone.

    - Tried to install same app with a new package name.

     

    That simply failed and displayed a window with "Unable to create process: Unable to install '<path>'. Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]"

     

    I believe I need to do more, but do not know what exactly. Google searches are not helpful. Most likely I am not choosing correct words.

     

    This has happened to me before and I did not solve it properly back then (changed package name back to default). I want to learn the way to do it right, now.

     

    Any help is appreciated.

     

    Thanks & regards,

    Ertan


  6. 23 hours ago, Dave Nottage said:

    1. This should at least have you started:

    Thank you. I have just slightly modified provided code to my taste and get rid of "deprecated" message for JObjectToID on Delphi 10.3.2.

    Final working for me version is below.

    
    uses
      System.SysUtils,
      Androidapi.JNI,
      Androidapi.JNI.Java.Net,
      Androidapi.JNI.JavaTypes,
      Androidapi.Helpers,
      Androidapi.JNIBridge;
    
     
    
    function BytesToHex(const ABytes: TBytes): string;
    var
      I: Integer;
    begin
      Result := EmptyStr;
      for I := Low(ABytes) to High(ABytes) do
        Result := Result + IntToHex(ABytes[I], 2) + ':';
      SetLength(Result, Result.Length - 1);
    end;
    
    
    function GetMacAddress(const InterfaceName: string = 'wlan0'): string;
    var
      LInterfaces: JEnumeration;
      LInterface: JNetworkInterface;
      LJavaBytes: TJavaArray<Byte>;
      LBytes: TBytes;
      I: Integer;
    begin
      Result := EmptyStr;
      LInterfaces := TJNetworkInterface.JavaClass.getNetworkInterfaces;
      while LInterfaces.hasMoreElements do
      begin
        LInterface := TJNetworkInterface.Wrap(TAndroidHelper.JObjectToID(LInterfaces.nextElement));
        if JStringToString(LInterface.getName).ToLower().Equals(InterfaceName) then
        begin
          LJavaBytes := LInterface.getHardwareAddress;
          if LJavaBytes <> nil then
          begin
            SetLength(LBytes, LJavaBytes.Length);
            for I := 0 to LJavaBytes.Length - 1 do
              LBytes[I] := LJavaBytes.Items[I];
            Result := BytesToHex(LBytes);
            Exit();
          end;
        end;
      end;
    end;
    
    

     

    23 hours ago, Dave Nottage said:

    2. Check the code (and warning) for GetUniqueDeviceID, here:

    It seems Mac address is still way to go. At least for a while.

     

    • Like 1

  7. Hello,

     

    As of Android 6.0 we cannot read mac address using an app as indicated in here: https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-hardware-id

    It seems some people have success reading it on network interfaces. I have seen some java code that I cannot translate and test on an Android 7.0 device. An example with several code alternatives: https://stackoverflow.com/questions/33159224/getting-mac-address-in-android-6-0

     

    1- If anybody can share some working code that would be appreciated.

    2- I have no information on how reliable device unique id on Android devices. I have that Chinese made hand held barcode terminal running modified Android OS. I cannot be sure if unique device id is actually globally unique independent of modifications to Android OS. Any information on that or links to read is appreciated.

     

    Thanks & regards,

    Ertan


  8. Hello,

     

    When I work on forms I have Style selection on screen.

    image.thumb.png.ff9d6d0b0a55018108ce3f8ebe6c1af7.png

     

    When I work on Frames, I do not see that Style selection and it always sticks to Windows Style even if my target is selected as Android.

    image.thumb.png.face6ec06f641704cb9216dbe633ac0f.png

     

    This makes it difficult to position some screen components.

     

    Is this a known problem or a feature of frames?

    Can I have platform specific design in a way with frames?

     

    Thanks & regards,

    Ertan


  9. On 10/8/2019 at 10:48 PM, Remy Lebeau said:

    That call stack shows the global TApplication object being destroyed, which in turn is destroying an internal TDictionary<String, TList<TFormRegistryItem>> object.  Looks like perhaps the destruction of one of the stored TFormRegistryItem objects is what is crashing.

    Does it also mean that I cannot be the source of the problem? I am not sure I used TFormRegistryItem t must be some visual component that I am using like TTabControl, TListView, TPanel, TLabel, TMemo, TImage etc.


  10. I could re-produce that error simply by running the app and once it is completely settled, closing it. Even for that I have spend several hours and tracked problem down to specific database operation(s). I use UniDAC and suspected that their native DBF (dBase) support might be the problem.

     

    I have remarked relevant code lines and continue my development. At some point, I needed these database operations and removed their remarks. It is very strange that after that error is not each time but random. I am not getting that error anymore, now. I do know same lines are called at each time and they are doing exact same things.

     

    If it appears again, I am going to directly check these database operations though.

     

    Thanks for the help.

    • Like 1

  11. Hello,

     

    I am using Delphi 10.3.2. There is an app for Android 5.1.1 platform only. It was working good. I do not remember when actually, but it was fine for sure.

     

    Problem now is that I get segmentation fault 11 when application is terminating. I cannot find in code reason why. I get following error in debugger after running Application.Terminate() or using Android back button which closes app:

    First chance exception at $00000000. Exception class Segmentation fault (11). Process Project1.apk (9547)

     

    Execution stops in System.pas at following lines:

    function _InstClear(var Dest: TObject): Pointer;
    {$IFDEF PUREPASCAL}
    var
      P: Pointer;
    begin
      Result := @Dest;
      if Dest <> nil then
      begin
        P := Pointer(Dest);
        Pointer(Dest) := nil;
        TObject(P).__ObjRelease;  // <-- Exactly right here
      end;
    end;

     

    My call stack at that time is something as following:

    image.thumb.png.b450070dfdc2a41c95f7b0b1762293a9.png

     

    Lastly, my local variables are as following:

    image.png.6a3cd4914f60e3fb3ecd164337548ea3.png

     

    I do not have anything complicated in that app. One thing which maybe relevant is that I pass some visual components (TMemo, TLabel) to a unit without form. These components are written text in them in a thread. I am using something like following to modify their values:

          TThread.Synchronize(nil, procedure begin BalanceLabel.Text := FormatFloat('#,##0.00', LocalBalance / 100); end);

     

    I have checked more than once to see if I am missing one visual component. I could not see any.

     

    I have googled with no luck. All my tests, debug runs returned no clue to me. Any hints to finding such FMX exceptions is appreciated.

     

    Thanks & regards,

    Ertan


  12. Hello,

     

    I am using Delphi 10.3.2.

     

    There is a project where I am communicating with another app (I will call it "other app"). Communication with other app is over clipboard. Other app is developed on Android Studio and is using some embedded device specific SDK. Other app is not a service app. It is a regular app without user interface (completely runs in the background). 

     

    If that other app is not running, my app runs it. Waits until it settles completely. Starts communication. I am now asked to close that other app when my app closes. Even if I could run it using an intent, I did not find any Delphi FMX example to close it.

     

    Embedded device is running Android 5.1.1. That is unlikely to change in a near future. I believe there maybe no problem of "dangerous permissions" or similar at that Android version.

     

    Any help is appreciated.

     

    Thanks & regards,

    Ertan


  13. I could use CryptoLib4Pascal cross-platform successfully with help from @Ugochukwu Mmaduekwe

     

    My test code looks like following:

    uses
      System.NetEncoding,
      ClpIBufferedCipher,
      ClpCipherUtilities,
      ClpIParametersWithIV,
      ClpParametersWithIV,
      ClpParameterUtilities;
    
    procedure TForm2.Button1Click(Sender: TObject);
    var
      Cipher: IBufferedCipher;
      KeyParametersWithIV: IParametersWithIV;
      KeyBytes: TBytes;
      IVBytes: TBytes;
      Buf: TBytes;
      PlainText: TBytes;
    begin
      KeyBytes := [31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36,37,38,39,30,31,32];
      IVBytes := [31,32,33,34,35,36,37,38,39,30,31,32,33,34,35,36];
      PlainText := TEncoding.UTF8.GetBytes(Edit1.Text);
    
      Cipher := TCipherUtilities.GetCipher('AES/CBC/PKCS7PADDING');
    
      KeyParametersWithIV := TParametersWithIV.Create(TParameterUtilities.CreateKeyParameter('AES', KeyBytes), IVBytes);
    
      Cipher.Init(True, KeyParametersWithIV); // init encryption cipher
    
      Buf := Cipher.DoFinal(PlainText);
    
      Edit2.Text := TNetEncoding.Base64.EncodeBytesToString(Buf);
    end;

    One who wants to use framework needs to put all directories & sub directories in Library Path, or use provided run-time packages. I did the former.

     


  14. 4 minutes ago, Dalija Prasnikar said:

    Depending on how AnsiString is used, it can be replaced with RawByteString in cross-platform. Only if it interprets stored characters and makes conversions, it cannot.

    It is just there are internal references and functions using that type. Moreover, it includes about 65kb big commonly used unit that needs a lot more modifications than converting AnsiString that I don't want to dig into.


  15. 2 minutes ago, David Heffernan said:

    Encryption is agnostic of framework. I don't see how you could have a VCL only encryption library. You don't need design time components. 

    I mostly use mORMot for my AES handling. Even it compiles on Linux FPC and Raspberry Pi, it doesn't compile for FMX. First compiler complaint is about AnsiString type.

     

    I tried pure Pascal Wolfgang Ehrhardt library and compiler is not happy with internal used type declarations in BType.pas file like

    type

      Str255 = string[255];

     

    So I'm asking for help from anyone who used an AES encryption under FMX.


  16. Hello,

     

    There seems to be a lot of VCL based free solutions. I could not find one for FMX platform.

     

    I am looking for a free AES256-CBC FMX compatible solution that I can pass IV and Key values manually.

     

    I installed "LockBox VCL and FMX 2.3" from GetIt package manager. It seems to take string value as Key for TLbRijndael component and does everything internally.

     

    Any help is appreciated.

     

    Thanks & regards,

    Ertan

×