TurboMagic 92 Posted February 28 Hello, this question is quite low level. For the purpose of being used from some completely different programming language on Android I'm trying to check if I can rework a Windows DLL of mine into a shared object. I can create a shared object (.so) already, for this one has to be aware that the library project type in Delphi which would create a DLL on Windows won't create a .SO on Android. I consider this a bug or at least a missing feature. But you can create a .SO by creating an FMX project and throw out the use of the default generated form (and everything in the begin / end block of the DPR). The resulting SO can be used if the functions/procedures are called dynamically. Next step would be to get a timer up and running. I tried the FMX time, but that didn't work, it crashes as soon as I want to create it (segfault 11). So I looked into how this one is implemented and copied that code into my application (to have as few connections with RTL and FMX as possible). But it crashes on creation as well. I looked what is done under the hood and it is this: The timer needs a JHandler and this shall be fetched via Androidapi.Helpers.TAndroidHelper, which has a MainHandler class property. This accesses a FMainHandler field and if that is nil, it is initialized, but that needs a TJLooper. As far as I understood (see https://developer.android.com/reference/android/os/Handler) this is the equivalent of the Windows message loop. Can I replicate that somehow in my SO? What would I have to do to get this working? My test project is attached. If you want to try it, compile the libSOTest.so first, then run libSOTestGUI. Best regards TurboMagic SOTest.zip Share this post Link to post
Rollo62 539 Posted February 28 Maybe that helps for your considerations? https://github.com/grijjy/DelphiPlatformTimerQueue https://blog.marcocantu.com/blog/2014_may_background_delphi_android_threads.html Share this post Link to post
TurboMagic 92 Posted February 28 Thanks for these links. The first one I know and already tried, but it crashes as well, but I need to try to understand their soruce better. I had thought to give TTimer a 2nd try as that one might be easier to understand. The 2nd link is really new to me. Share this post Link to post
Rollo62 539 Posted February 28 (edited) There is another timer implementation within Kastri https://github.com/DelphiWorlds/Kastri/blob/a1ae5aec3146e4c4c61999e2ce8adcb281474a64/Core/DW.OSTimer.pas#L4 Quote * DW.OSTimer - leaner, less complex implementation of a timer. Also does not rely on FMX, so can be used in an Android … Edited February 28 by Rollo62 Share this post Link to post
TurboMagic 92 Posted February 28 While Marco's blog post is nicely written it's not excactly what I'd need. Threading is not really new to me, but I would have the need to wait in there or so. But the Kastri Timer is something I really should look at. Thanks for bringing that one up! Share this post Link to post