Quantcast
Channel: Delphi Worlds
Viewing all 80 articles
Browse latest View live

Delphi Worlds 5th Anniversary

$
0
0

I started this blog back in September of 2013. With the 5th Anniversary this month, I figured it is time to tell some of the story..

First languages

My first programming language was APL, which I partly learned in high school as a small part of Mathematics classes. This lead to me becoming part of what was called “Computer Club”, where a teacher gave up part of his lunchtime to help students learn about computer programming. The teacher also introduced us to BASIC, and when devising our programs we would fill out computer “cards” that would be sent to a computer centre in our capital city (Adelaide), where the cards would be read by a card reader, the computer would execute the programs, and we would receive a print of the results; a complete turnaround time of about a week!

Enter Pascal

Not long after I learned of Pascal, and instantly fell in love with it. One of my first experiences with it was writing programs on my father’s computer using a BASIC program that would be able to take Pascal source, and execute that (from memory, it would turn it into assembler code).

The first computer of my own was a Microbee (which runs the CP/M OS). One of the reasons I chose it was because at the time I predicted that the IBM (and various clones) would not take off (how wrong was that call?). On that computer I used Turbo Pascal 2.2 for CP/M, and back then there was no concept of units. In order to have larger programs, you would need to use what were called “overlays”. Version 4 was a total game-changer, however by the time I upgraded (to 5.5) I had moved on to owning a PC, which I initially considered heresy!

Turbo Pascal for Windows: the “father” of Delphi

When Windows first came out, I also figured that wouldn’t last, because it looked too clunky. I mean: what’s with not being able to have windows overlap each other? This time Windows 3.1 was a game changer because it was far less crash-prone, introduced True Type fonts, included drag-and-drop, and more! I knew then that I should delve into the magical world of Windows programming.

Soon after the release of Windows 3.1 came Turbo Pascal for Windows 1.5. When I started using it, all I could think was “Wow, I can write programs for Windows in my favourite language!”. One of the first things I wrote with TPW was a basic card game, based on “Switch” (a bit like Uno), which I enjoyed playing with my brothers. Unfortunately however, writing apps for Windows with TPW meant having to write way more code than I was used to.

Enter Visual Basic: a development tool that not only allowed you to write for Windows, it was way easier because you could design everything visually, and it didn’t require as much code to write. Around mid-late 1993, I reluctantly started to write programs with VB, in the hope that sometime soon the magicians at Borland would come up with something even better.

Entering the world of Delphi

Around January of 1995, I heard (or read?) rumours that Borland were on the cusp of releasing something akin to VB, and it was being dubbed the “VB killer”. I was a bit cynical at the time, however of course on February 14th, 1995, Delphi was released upon the world, and it certainly lived up to my expectations: it had a visual designer, ready-made components, and it also supported importing VB controls! I figured I would never, ever have to use VB again, though briefly in 1998 I had to endure working on a project that used it.

That’s the story of how I came into developing software with Delphi. At first it was a hobby, though I did use it to some extent “under the radar” at my work between 1995-1997, until I turned professional in 1997 and since then I have used it every single year (though not every single release, but most of them).

Enter Delphi Worlds blog

Fast-forward to 2013, and after posting blog articles elsewhere, and only very occasionally, I decided to start my own blog, hosted on my own site. When I came up with the name, I thought about the fact that Delphi was now cross-platform, and that opened up a number of new “worlds” for developers.

One of my first criteria for the blog was (and still is): no ads. I was disillusioned with having to read articles other sites that had ads plastered all over because they just add too much noise. My main aim is to share what are “challenges” to developers that they might otherwise spend ages having to work out how to implement. Having said that, they are usually also of special interest to me, i.e. they’re something that I’ve had to solve for myself.

Time…

Nearly all of the time spent on the articles I present here is my own, i.e. I’m not compensated in any way for it (especially with no advertising here). As much as I do this out of my passion for Delphi and to help others, there is now another way to help motivate me, and that is through the “Donate” link at the top right of this page, and at the bottom of this article. Your donation can be as little or as much as you wish, and whatever the amount is, it will be much appreciated, and help continue my work here.

I thank you for your support and your time.

 


Codex Delphi Add-In

$
0
0

This article describes a Delphi add-in that I’ve been working on, of which the first version (1.0.0) has been released today

In the beginning..

Some time ago I started working on an add-in for Delphi to add some functionality that I wanted in the IDE, one of them being that I’d like it to remember that last project loaded, so that when the IDE is restarted, that project can be loaded automatically. I also wanted the File|Open functionality extended so that I could have favorites, which would use the favorites configuration from another Delphi add-in: GExperts.

Assisting with mobile development

At the ADUG Symposium earlier this year, I presented a session on some of the hurdles that need to be overcome in order to develop applications for mobile, and this included configuring splash images and icons, so I expanded my add-in to include the ability to find images and icons that have been created, and replace the entries in the Project Options, rather than assigning each one manually.

The problem with Project Options

Speaking of the Project Options dialog, I had difficulty with it during the presentation because the display that was being used for the projector was a lower resolution, and as a result the top and bottom of the dialog were off-screen, and it wasn’t possible to make the dialog any smaller. I figured there must be a way of being able to make it smaller using an add-in, so I worked out how to do that, and included it in the add-in.

Adding in Android tools

Since I was spending time expanding the add-in, I figured a logical step would be to include the functionality of the ACTED tool, which combines a number of functions related to developing Android applications.

Documentation

There is some basic documentation, as well as where to obtain the installer, at the Codex page, where you can also read about the other features.

Future plans

I am working on a couple of other features, including a logcat viewer (for Android), an assistant for the deployment manager to help with adding files in bulk, a tool for determining unit dependencies, and more..

I hope that Codex helps boost your productivity when using Delphi.

Delphi 10.3 Rio has arrived!

$
0
0

It’s time to become excited, because Delphi 10.3 Rio has been released!

Rather than go over all the new features here, please refer to the Embarcadero website, and the docwiki for a full list.

Of special interest to me are:

  • The out-of-the-box support for Android API 26+, so if you’re using Rio, there’s no longer any need for my special workarounds as per my earlier articles.
  • Android Native Controls and FMX styled controls on the same Android form.
  • Improvements in the IDE: I like the new look, though the invasion of the “space monster”* will likely upset those who like to have their systems in larger scale, or those who use lower resolution monitors (such as with some projectors). I’ve also moved over to the “dark side” because the dark theme support is looking better.
  • iOS 12 support.

If you prefer ESD (Web) install go here, for ISO go here, and here for a full list of the fixed issues.

(*”space monster” refers to the amount of extra spacing that has been added in some places in options dialogs)

Codex 1.1.0 for Delphi 10.3 Rio

With the release of Delphi 10.3 Rio comes the release of Codex 1.1.0, which also has support for Delphi 10.2 Tokyo, however support for Delphi 10.1 Berlin has been dropped. (Codex 1.0.0 has support for Berlin and Tokyo)

New features:

  • LogCat viewer – no more need to run Monitor to see what’s going on in your device! More filtering options will come later..
  • Java2OP “front end” – run the Java2OP import tool from right in the IDE!
  • SDK Frameworks Import – The ability to add multiple frameworks at once, into an existing SDK in the SDK Manager, or into the SDK defaults
  • Option to show the project manager when opening a project or group

Check out the full list of features, and how to download.

 

 

Celebrate Delphi’s birthday with Delphi 10.3.1 update!

$
0
0

On February 14th, 1995, Delphi was brought into the world, and it changed the software development landscape. Now 24 years later, Delphi is still going strong, with the ability to target multiple platforms from single source.

This milestone is being celebrated with the release of the first update to Delphi 10.3 Rio, which contains a number of enhancements and fixes to over 150 user reported issues.

Fixes of special interest to me are:

  • Notifications for iOS >= 10
  • Linking of newer versions of some third-party iOS SDKs (e.g. Firebase and Facebook) to iOS 12 SDK
  • Use of 9-patch images on Android
  • Warning toast on Android 9
  • ..and a bunch of other fixes for FMX issues

Head over to the official announcement for more details.

A fix for using TMapView on Android 9 devices

$
0
0

A recent report on Embarcadero’s Quality Portal caught my attention today, where an app would crash if it used a TMapView on an Android 9 device. Fortunately, I had just recently updated my Nexus 5X to Android 9 (thanks to Brian Long’s help), so I could investigate the problem.

First thing to do was to create a new project, place a TMapView on the form, populate the apiKey value in the project options:

..and check the Maps Service checkbox in the Entitlements section:

Next, I fired up Monitor, which comes with the Android SDK tools (run monitor.bat, which is in the tools folder from the root of the Android SDK) and start the Android app. Lo and behold, when the app crashed, the logcat messages indicated an error:

A quick Google of the error (searching on “Failed resolution of: Lorg/apache/http/ProtocolVersion”) revealed a discussion on StackOverflow, and more importantly, what to do about it. The solution is incredibly simple: just add a tag to the AndroidManifest.template.xml:

the text is:

  <uses-library android:name="org.apache.http.legacy" android:required="false" />

..and all is good in the world again!

Codex 1.2 Released

$
0
0

Yesterday, I uploaded a new version of Codex to the Github repository that has the installers.

Main new changes in this version:

Editor Tabs Position

There’s now an option (in Tools->Codex->Options) to have the editor tabs (e.g. Code | Design | History) appear on the left, just like they used to! If you also have CnWizards installed, you will need to disable the FeedReader Wizard (Tools->CnPack->Options, Wizard Settings) in order for the editor tabs option to work consistently, until CnWizards is fixed. The editor tabs option has the odd quirk where the tabs may not always appear on the left, however I’m working on resolving this in the next update to Codex.

Feed Alerts

Monitors feeds (Atom or RSS) that you’d like to be “alerted” about, such as new entries in the Embarcadero Quality Portal, or on Code Central (such as updates to Delphi), or perhaps new questions about Delphi on StackOverflow.

Updated Image Assets feature

The Image Assets feature has been updated to support the changes in Delphi 10.3.1 regarding splash and icon image sizes for iOS.

 

Happy coding!

Delphi 10.3.2 released, and introducing… Mosco!

$
0
0

The latest version of Delphi Rio, 10.3.2 has been released! To coincide with the release, Delphi Worlds introduces: Mosco

Mosco (an acronym for MacOS Companion)

Mosco is a combination of a macOS 64-bit application and an expert (of the same name) for Delphi.

Mosco has functionality that has yet to be seen:

  • An much enhanced experience of adding frameworks to SDKs (lists all available public frameworks in the SDK)
  • Instantly switch between SDKs, including for macOS, iOS and Android
  • Instantly switch between connection profiles
  • Open Finder on the Mac to show where the deployed app is located
  • Prompt when attempting to launch an app on an iOS device when the device is locked

The Mosco macOS app provides an alternative to PAServer Manager, allowing you to manage multiple versions of PAServer on the Mac, informing you when a particular version is already running.

Planned features for future versions of Mosco (not set in stone):

  • An alternative experience (to Delphi’s built-in) Notarization (for macOS apps)
  • Integration with DeviceLens (currently in beta), so you can monitor logging from your iOS devices from your Windows machine or VM

Mosco uses code recently added to (or improved on) the Kastri Free project, including:

  • TStatusBarMenu – allows your macOS apps to run as an “accessory” (appears in the status area of the menu bar)
  • TThreadedTCPClient – used by the Delphi add-in to communicate with the macOS app

You may download the version 1.0.0 beta from here, and some brief documentation is in the ReadMe.  Note that to use the Delphi add-in you will need to create a registry entry in the Experts key, which points to where you have downloaded Mosco260.dll to. An installer and more documentation will come later.

I would love to hear people’s feedback (please comment on this article) about Mosco. If you have issues or enhancement suggestions, please visit here.

Delphi Rio 10.3.2

Amongst the new features of Delphi Rio 10.3.2 that are of greatest interest to Delphi Worlds are:

  • Support for building macOS 64-bit applications
  • Bug fixes!
  • Inclusion of FMXLinux
  • Enhanced Firebase Android support
  • IDE improvements

Now you can finally take advantage of the 64-bit only macOS frameworks such as Accounts, AVKit, Contacts, LocalAuthentication and MapKit (among others). Along with being able to build 64-bit applications for macOS, 10.3.2 also has the ability to notarize your applications so that you don’t necessarily need to distribute them via the Apple Store.

There are reported to be over 400 individual (i.e. excluding duplicates) bug fixes in this point release.

With the introduction of FMXLinux, building GUI apps for Linux with Delphi will again be a reality!

In this version, Embarcadero introduce their implementation of Firebase Cloud Messaging support.

Also good to see that the IDE quirks that were noticeable when theming was introduced have been greatly improved upon!

Notarizing your macOS 64 bit apps built with Delphi

$
0
0

The recent release of RAD Studio 10.3.2 includes being able to compile your apps for macOS 64-bit, and allows you to notarize your apps right from the IDE. In this article, I cover the notarization process from end to end.

What is Notarization?

Notarization is the process of “signing” your macOS application so that you can distribute it via means other than the Mac App Store. Starting from macOS 10.15 (Catalina), all apps that run on the Mac need to be notarized, or be distributed via the Mac App Store, otherwise they simply will not be allowed to run.

If you’re interested in more information about how notarization is applied, please watch this video from WWDC 2019. (runs approx 33 mins)

In order to notarize your macOS application, you need to have an Apple Developer Account so that you can obtain a Developer ID Certificate, and an application specific password.

Obtaining a Developer ID Certificate

Given that you have an Apple Developer Account, there are two ways to obtain a Developer ID Certificate. One is substantially more straightforward, especially if you have already set up your developer account in Xcode:

Via Xcode:

  1. Start Xcode, click on Preferences, and select the Accounts tab:
  2. Select the developer account you wish to create a Developer ID Certificate for
  3. Click Manage Certificates
  4. Click the “+” dropdown button in the bottom left
  5. Click Developer ID Certificate.

That’s it! Xcode generates the certificate for you, and adds it to the Keychain. If you open the Keychain Access app (in /Applications/Utilities), you should see the certificate there:

Via the Apple Developer website:

The alternative is to go to https://developer.apple.com and log in using your developer account Apple ID, select Certificates, IDs and Profiles, click the plus button:

..select the “Developer ID Application” option, and follow the instructions. I won’t go into any further detail for this process, as it is really much, much easier to do it via Xcode.

Obtaining an application specific password

Please follow the instructions for an application specific password, here.

The website to visit to create the password is here, using your developer account Apple ID to log in

Providing the notarization details in Project Options

  1. In Delphi, open your application, and bring up the Project Options
  2. In the list on the left, select Deployment -> Provisioning
  3. In the Target combobox, select macOS 64-bit for the highest configuration for which you wish to apply the settings e.g. “All configurations” if you wish to apply the settings to all configurations
  4. In the Build Type combobox, select: macOS 64-bit Developer ID
  5. Enter the Apple ID you used to create the application specific password in the Apple ID edit
  6. Enter the application specific password you created earlier (you did remember to save it somewhere, yes?) in the App-specific Password edit
  7. In the Developer ID Application Certificate edit, enter the full description for the Developer ID Certificate you created earlier, e.g: Developer ID Application: Joe Smith (JHF5SD7N)
  8. If you wish to have the process staple the notarization ticket to your app, check the “Attach a ticket…” checkbox. This is recommended, otherwise macOS needs to check-in with Apple servers to see if it’s okay to run, which requires an internet connection.
  9. In the list on the left, select Application -> Entitlement List
  10. As per step 3, select the applicable Target
  11. Check the “Allow unsigned executable memory” option. In later versions of Delphi, this will be set by default.

Notarizing the application

  1. Select the Developer ID build type in the Project Manager, e.g:
  2. Deploy the application:

Delphi will do all the necessary steps to notarize your application. The notarization step can take a couple of minutes, depending on how busy Apple’s servers are. It will take a further couple of minutes or so while the IDE waits for the notarization status to be updated.

If there are issues during the notarization process, it may be helpful to turn on the verbose setting in PAServer:

As it outputs all the commands and results, which may be helpful in diagnosing the problem(s).

I hope this helps clarify the notarization process, at least until more complete documentation is available on the RAD Studio docwiki.


Using iOS simulators with Delphi

$
0
0

If you’re starting with a newer version of Xcode on the Mac, you will find that the iOS simulators supplied will not work with Delphi (as at version 10.3.2). In this article I describe the procedure for working with the older iOS simulators.

Adding older simulators in Xcode

  1. Open Xcode on the Mac, and click Window > Devices and Simulators, or just press Shift-Command-2, and click the Simulators tab
  2. Click the + button that appears in the lower left of the window:

     

  3. Select a simulator device that is available for iOS 10.3. The following is a list of those devices:iPhone 5
    iPhone 5S
    iPhone 6
    iPhone 6 Plus
    iPhone 6S
    iPhone 6S Plus
    iPhone 7
    iPhone 7 Plus

    iPad Mini 2
    iPad Mini 3
    iPad Mini 4
    iPad Air
    iPad Air 2
    iPad (5th generation)
    iPad Pro (9.7-inch)
    iPad Pro (10.5-inch)
    iPad Pro (12.9-inch)
    iPad Pro (12.9-inch) (2nd generation)

  4. Click Create:

     

  5. Repeat steps 2-4 for the devices you wish to have simulators for.

Refreshing the list of simulators in Delphi

Make sure you have imported an iOS simulator SDK. It won’t matter what version it is; I’m unsure as to why this is so.

  1. In Delphi, start a new FMX project, or open an existing one
  2. In Project Manager, expand the Target Platforms node, and expand the iOS Simulator node
  3. Right click the Target node, and click Refresh:

This should make the simulators that you added appear in the Targets list. You may target those that you added.

Introducing Device Lens.. and Codex 1.2.1 released

$
0
0

Codex had a feature where you can launch a logcat viewer for displaying logs for Android devices. This feature has now been moved out of Codex (in version 1.2.1)  into a separate application: Device Lens

Device Lens 1.0.0 has just been released, and you may find it here. There is some basic documentation at the link, however if you have questions or issues, please create an issue at this link.

At present, Device Lens provides displaying of logs for Android devices, however Device Lens 1.1.0 is planned to be able to display log messages for iOS devices. This would be made possible by Device Lens communicating with the macOS companion application: Mosco, so that your iOS devices can remain connected to the Mac, and be able to debugged using Delphi at the same time.

As per the title of this post, Codex 1.2.1 is also released (this release is for Delphi Rio 10.3.x only), which includes a few bug fixes.

Integrating iOS support with Delphi’s FCM

$
0
0

Before the release of Delphi 10.3.2, Embarcadero released a patch for including FCM (Firebase Cloud Messaging) for Android in your apps, and now that support is included in Delphi 10.3.2. This article describes how to include support for iOS in FCM.

TL;DR: The demo for including iOS in FCM is here. Note that it depends on other files in Kastri Free.

This solution is based around existing code that is used in my FCM solution, presented here. I created a unit (DW.PushNotification.iOS) which is similar to FMX.PushNotification.Android, that is meant as a “replacement” of sorts for FMX.PushNotification.iOS.

This new push notification unit uses other units from Kastri Free to provide the necessary implementation for iOS. It also relies on framework files from the Firebase 6.2.0 iOS SDK, however those that are required are also part of Kastri Free. The key things to remember for iOS when you’re including it in your own project are:

  • Add GoogleServices-info.plist (download it from your project in Firebase Console) to your deployment (use a Remote Path of ./)
  • Include -ObjC in the “Options passed to the ld linker” setting in the Linking options, which is under Building\Delphi Compiler in the Project Options. You’ll soon know if you’ve missed this because your app will crash on startup.
  • Include paths to the Firebase SDK frameworks (these are in the Search path in the Project Options of the demo for iOS Device 64-bit configuration)

Go here for information on how to configure your app for FCM for Android.

As described above, the demo for this solution can be found here. It has had fairly minimal testing, so if you have any issues, please report them here.

Using OpenSSL with Indy in notarized apps on macOS

$
0
0

The requirement for macOS apps to be notarized has thrown a few challenges, one of them being that developers are having trouble with apps that use Indy components with SSL. This article describes how to overcome that issue.

Rather than dive headlong into working out why the notarized app would not work, I decided to “start from scratch” (in a way), and work out how to build the dylibs for macOS. The results are located here (i.e. macOS binaries for OpenSSL, version 1.0.2s).

The binaries need to be added to your application via the Deployment Manager, and the Remote path value for each binary is: Contents\MacOS, e.g:

Note that in this picture, I have selected All configurations for macOS 64-bit, so that both Debug and Release are shown.

In the project source, add System.IOUtils and IdSSLOpenSSLHeaders to the uses clause, and call IdOpenSSLSetLibPath, like this:

program NotarizedIndy;

uses
  System.StartUpCopy,
  System.IOUtils,
  FMX.Forms,
  IdSSLOpenSSLHeaders,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  IdOpenSSLSetLibPath(TPath.GetDirectoryName(ParamStr(0)));
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

After compiling and notarizing your application, you should find that Indy with SSL now works.

Tools that I use

$
0
0

In this post, I’ll be taking a look at some of the tools that I use in the process of software development that I swear by. It’s not all about Delphi 😉

Before around 2011, I used to be a bit of a “it’s Windows or nothing” kind of person. When I started down the path of developing for iOS and macOS, all that changed; I needed a Mac to be able to develop for those platforms, so I started using one and have never looked back. Most of the tools I use I prefer the Mac version, because it means not having to fire up a Windows VM to run the tool. Today I’m presenting a list and a summary of some of the tools I use. In future I’ll revisit some of these and cover them in more detail in terms of how/why I use them.

Here’s a list of those that I use most:

VirtualBox

Of course to use Delphi I still need Windows, so for the most part I have been using VirtualBox to create Windows VMs to run Delphi on.

Parallels

When a new release of Xcode and/or macOS comes out, as many of you may know, Delphi has not always “played nice” with them, so having a VM of macOS to test out Xcode has been essential. Unfortunately, VirtualBox has not always been able to keep up with changes in macOS, so a while ago I decided to use Parallels for running macOS VMs, on my Mac 🙂

Laravel

Whilst Delphi is an excellent product for creating back-end applications, PHP applications are relatively easily deployed on any platform (including Raspberry Pi running an ARM Linux variant), and my PHP framework of choice is Laravel. I stumbled upon it around the beginning of 2017 and was very impressed. It can be used to create the front-end part of the application using its Blade templating engine, however it also plays very well with Vue. Laravel is quite mature now, and has a large thriving community.

TablePlus

I’ve just recently come across this one, after being a long time user of Sequel Pro. TablePlus supports a number of databases, has a much nicer UI and supports dark theme.

Insomnia

As with TablePlus, I’ve just recently come across Insomnia, which is an awesome REST testing tool. I find it is much “cleaner” and easier to use than PostMan.

Visual Studio Code

Any editing that I need to do outside of Delphi, I use Visual Studio Code, including all my Laravel work, editing of Java source for jars included in my Delphi projects, and a whole bunch of other files.

Fork

Fork is a graphical git client that runs on macOS or Windows, and is the best one I’ve come across. It’s also free!

Slack

Slack is a collaboration tool that is probably used mostly for chat, however it also allows integration of many other applications such as Github, JIRA, Google Calendar, Outlook, Zoom, Trello and more. You and your team can receive notifications right in the Slack channel that subscribes to those applications. One of Slack’s biggest drawbacks is that usually someone who is already on the “team” needs to invite others. Fortunately there are ways of having people “invite themselves”, including using a small PHP application that automatically sends the invite, such as the one I use where you can invite yourself to the Delphi Worlds Slack team 🙂

Here’s a list of tools that I have developed myself:

Codex

An add-in (or expert) for Delphi that adds functionality that I use all time, including

  • Building a jar from Java source, so that it can be included in Delphi projects
  • A front-end for Java2OP, to help import Java classes into Delphi units
  • Image assets manager for easily configuring splash screens and icons for mobile projects.

..and it also includes (amongst other things) some “tweaks” for the IDE.

Mosco

Mosco (MacOS COmpanion) is a combination of an add-in for Delphi and an application that runs on the Mac. It supplements what PAClient and PAServer do.

Device Lens

A tool for displaying logs emitted from mobile devices. Presently, it supports viewing logcat output from Android devices, however support for viewing iOS device logs (via Mosco) is in the works.

Cross-platform location monitoring

$
0
0

Previously, I have written two articles on monitoring location changes: one for iOS, and one for Android. This article and the related demo brings everything up-to-date and merges support for both operating systems.

STTP (Straight To The Point – I’m coining an acronym to replace TLDR)

If you’re just after the demo, you may find it here. As with most demos in the articles in this blog, it is dependent on the Kastri Free library. Please be aware that for iOS you will need to apply the System.iOS.Sensors patch as detailed below.

Requirements

As per the previous articles, the aim is to be able to monitor location changes reliably, including when the application is not running. Due to restrictions introduced in later versions of Android, and some shortcomings in the iOS implementation in Delphi, there some “hoops to jump through” to make this all happen.

Project Groups

The demo has 2 project groups: one containing the application and service (CPLAndroidGroup), and one that contains just the application (CPLAppOnlyGroup). CPLAppOnlyGroup is useful for compiling for iOS, because if you compile just the application in the CPLAndroidGroup for iOS, the IDE will still compile the service, regardless of the fact that you are not compiling the application for Android. This issue has been reported, here.

Grijjy Cloud Logger

You may notice in the code that use is made of the excellent Grijjy Cloud Logger framework. This has been useful for debugging so I have left the code in, and if you want to use it, you will need to add defines (CLOUDLOGGING) in the Project Options for the supported platform targets.

Unfortunately at present there is no support for Grijjy Cloud Logging on Android 64-bit. Hopefully this will be rectified soon.

If you choose to use Grijjy Cloud Logging, you will need to either define user override environment variables in the IDE options that correspond to the library locations:

..or modify the project search paths to point to the required libraries.

You will also need to modify the value for cCloudLoggingHost in the CPL.Consts unit in the Common folder, to point to your cloud logging broker instance.

Application

The application has been refactored to integrate the iOS implementation to make things work smoother, and hopefully be easier to follow. Notably, it now includes the DW.ServiceCommander.Android unit, which contains:

TServiceCommander

This class:

  • Handles the BecameActive and EnteredBackground application events, sending a local broadcast to the service to inform it of the change so that the service can enter or exit foreground mode.
  • Has a StartService command that starts the service if it is not already running.
  • Has a SendCommand method to send any other commands that the service needs to receive.

DW.Location unit

This unit and the units it uses contain the classes necessary for integrating iOS support, and for Android for receiving location messages from the service. The iOS implementation uses TLocationSensor which comes with Delphi, however there are some customizations that are necessary, which are detailed later in this article.

Android Service

On Android, the application needs a service, and since it needs to be able to track location when the app is not running, it needs to start when the device starts. As per the previous Android demo, instead of using TLocationSensor, I chose to write custom code; mostly for more control, and also so that it can be easily “swapped out” for another implementation such as one that uses FusedLocationProviderClient.

The ServiceModule has been refactored to decouple some of the functionality, namely:

TBackgroundMonitor

The OnScreenLockChange event is fired when the screen is locked.

When the device enters “doze” mode, an alarm is set so that the service will be invoked when the alarm fires, and the OnDozeChange event fires so that any additional action may be taken.

TLocationUpdater

This class is responsible for processing the location update. It may send the location details to a server, and/or store the location in a local database.

TLocation

This class existed in the prior version of the demo, however it has been refactored somewhat to improve reliability.

Starting the service at boot time

The service starts when the device starts by using a broadcast receiver (A Java class called DWMultiBroadcastReceiver, in dw-kastri-base.jar) which is configured in AndroidManifest.template.xml

The android.intent.action.BOOT_COMPLETED and android.intent.action.QUICKBOOT_POWERON intent filters ensure that the broadcast receiver receives these intents on cold boot and restart. In the Java code for DWMultiBroadcastReceiver, the metadata is checked for an entry named DWMultiBroadcastReceiver.KEY_START_SERVICE_ON_BOOT, and the metadata value is used as the name of the service to start:

Note that DWMultiBroadcastReceiver also exists in dw-multireceiver.jar, however I am in the process of merging Java code used in Kastri Free in an effort to reduce the number of jar files.

Considerations for later versions of Android

In Android 10, using location services via a service requires requesting a runtime permission of android.permission.ACCESS_BACKGROUND_LOCATION, so this permission is added to AndroidManifest.template.xml (the permission cannot be  configured via the IDE), and the permission is requested in code.

From Android 8, a service is required to start in foreground mode if the application goes to the background or is not running. The previous demo went some way to solving this, however it was not 100% reliable; this demo should work as it should. Since the demo uses a regular service, when starting in the foreground the service needs to post a notification which is visible in the status bar, and a banner is visible in the lock screen. Although this is a tad intrusive, presently it’s the only option using a plain Service constructed in Delphi, as using an Intent Service is currently broken in Delphi.

iOS

Delphi implementation issues

As per the previous article about location monitoring on iOS, the main issue is that using TLocationSensor “out of the box”, location updates do not occur when the application is in the background or the application is not running. The easiest way to solve this was to patch the System.iOS.Sensors unit, which uses code from the DW.iOS.Sensors unit to help manage the usage (e.g. When In Use and Always), background status (normal and significant changes) and activity (such as Auto and Fitness).

Applying the System.iOS.Sensors unit patch

The easiest way to apply the patch is with Codex, using the Source Patcher function:

If you have not already installed the Patch executable, there is a download link in the Source Patcher dialog:

After downloading/installing, you will need to change the name of the executable to something other than patch.exe (such as p.exe), as Windows thinks it is some kind of installer and will not run without elevated privileges.

Select the patch executable, source file, patch file, and destination folder, e.g:

The System.iOS.Sensors.10.3.3.patch file is supplied with the demo in the Patches folder

The patched code in the resulting file is indicated by comments beginning with // DW, so they’re easy to find.

Testing the demo

I would like to have done more testing on this demo than I have (so far), however it can be rather time consuming, since some of the “live” testing requires physically moving from place to place. I’d like to once again thank Atek Sudianto from Jakarta, for running this demo through its paces.

Android

Normally a device will not go into “doze” mode until a couple of hours of inactivity, when not connected to any charging source. This can make it difficult to debug since debugging normally requires the device to be plugged in to the computer doing the debugging, however I stumbled across a technique for “faking” doze mode. Long story short: it’s via an adb command, and I have now integrated this function into Device Lens:

As pictured, click the “minus” button to fake doze mode, and the “plus” button to restore it to normal.

To test the service starting at boot, either turn the device off, then back on again, or use the device’s reset facility. Shortly after the device starts, you should see the notification icon for the app (default is the Firemonkey icon) in the status bar. This is because the service has started in foreground mode, which requires a notification being displayed.

If you then start the application, you should see the notification icon disappear, because the service has exited foreground mode.

iOS

Location updates on iOS when the app is in the background or not running have been exceedingly frustrating (regardless of the issues in Delphi) ever since I’ve started using them. When first testing this new demo, I found that it did not appear to be generating updates, despite the device having moved significantly (more than 500 metres, apparently), then after a while (a day or so), location updates started happening (there were no code changes), without the device moving significantly.

I’d be interested to hear from others about their experiences with background location updates on iOS (using their own code or the demo from this article), so please feel free to leave a comment.

Looking to the future

I have been working on an implementation of location updates that uses FusedLocationProviderClient, however it has been left out for now due to time constraints.

I am also looking into solving the intrusive notification that shows when the service is in the foreground on Android. Indications are that a JobIntentService should be used, however as described earlier this is currently broken in Delphi, though I am looking into solving that issue, as well as investigation other methods.

Finally, hopefully the location services issues for iOS in Delphi will be solved in Delphi 10.4, removing the need to patch the Delphi source.

Expanding Embarcadero’s FCM implementation, revisited

$
0
0

Back in October last year, I wrote about integrating iOS support for FCM using Embarcadero’s implementation. In this article, I describe a revised demo that simplifies things and fixes a couple of issues.

STTP

The new demo can be found here. Please be aware that the ShowBannerIfForeground must be set to False if you don’t want a banner showing while the app is in the foreground, and that both data and notification elements must be present for Android push messages when the app is running, for everything to work as expected. See below for more details.

The new demo

The previous demo was basically just an expansion of example code presented by Embarcadero when their support for FCM (Android only) was introduced. The new demo encapsulates that code into its own unit, so all that needs to be done is to create an instance of the class (TPushNotifications) and assign a couple of event handlers.

The issues

Showing a banner when the app is not running

One of the main issues with the FCM implementation for Android is that a banner does not show when the application is not running, i.e. all that shows is the notification icon in the status bar.

The banner shows only if the Importance of the channel is set to High, so the startup code in TPushNotifications creates the channel, and sets the Importance to High. The channel id is extracted from the application metadata (in AndroidManifest.xml) using some code recently introduced into the Kastri Free library (DW.OSMetadata.XXX units).

Much larger issues

There are some extremely annoying quirks with FCM on Android, and I’m hoping I’m just doing something wrong and that someone can point it out, however from what I’ve discovered:

When an app is in the background (i.e. still running, but not in the foreground), in order for a notification to be received, the payload must contain a data element. However, if the app is not running at all, the payload must contain a notification element, otherwise no notification is presented.

In addition, when the app is in the foreground, no banner shows at all. To allow for this, I’ve updated the code to present a local notification, which will show when the ShowBannerIfForeground property of TPushNotifications is set to True. Note that this property applies to Android only, as it works on iOS.

Now all will work as expected, as long as messages sent to Android devices contain both a notification and data element (they can contain the same data).

Configuration

Remember to import your google-services.json file for Android:

..and to provide your Google-Services.info.plist for iOS (for the demo, it will go in the Resources folder)

Sending messages

I’m planning an article which covers creating a server which includes sending messages, however for now for testing you could use the standalone testing tool: PushIt.

As above, messages to Android devices should contain both a notification and a data element for everything to work correctly. Here’s an example payload:

{
  "to":"fDYt7NwXGyM:APA91bE_5ACVjyRubh3-s_kRD6Ig83LX8VKcsEFCxIfDemw49AIHudDGVQwnJ5r1UMlPBc2A2P6yrEZ6fbBsejrHaX5vQQ-RdpUbRiRk1UURknTDrJfMIMqkTZGd0mstxLWsMaI-pWjl",
  "notification":{
    "android_channel_id":"EMBTFCMv2",
    "title":"Testing.. 1..2..3..",
    "body":"FCM still rules!"
  },
  "data":{
    "android_channel_id":"EMBTFCMv2",
    "title":"Testing.. 1..2..3..",
    "body":"FCM still rules!"
  }
}

For iOS, there should be a notification element only.

Conclusion

I sincerely hope that I’ve missed something in regards to what needs to be in the payload to make things work as expected on Android, so if anyone can shed some light on the problem please let me know, however I do know that using the methods above works.


Fixing gesture “lag” near the screen edge on iOS

$
0
0

An enquiry I had from a Hans Jakobsen of EarMaster (brilliant music teaching software for PC, Mac, iPad and iPhone) recently was regarding an apparent “lag” for the OnMouseDown event for controls near the edge of the screen on devices with later versions of iOS. This article poses a workaround for the problem.

A description of the problem

Hans had already done some research about the issue, and came across this link, and he asked me to look into how to solve it in Delphi.

Implementing preferredScreenEdgesDeferringSystemGestures

Firstly, I needed to find exactly where to implement the changes. The article says that in order to indicate which edges should take “precedence” (over system gestures) in your app, the preferredScreenEdgesDeferringSystemGestures method needs to be “overridden” in the class that implements UIViewController. In the case of Delphi, this is TFMXViewController in the FMX.Platform.iOS unit. Fortunately, this class is declared in the implementation section, so the unit can be “patched” without having to recompile any other units. It was then a simple matter of adding the method to the FMXViewController interface and implementing it in TFMXViewController (see changes below)

Telling iOS which edges to prefer

Next up was how to determine what edges are “preferred”, so I used an old trick of defining a property that could be set outside of FMX.Platform.iOS, which that unit could then use. The DW.ScreenEdgeManager unit declares a record called TScreenEdgeManager, which has a private field FPreferredScreenEdges which is a set of the desired “preferred” edges. The private field value is set inside the SetPreferredScreenEdges method, and that method ensures that the changes are flagged in the system by calling setNeedsUpdateOfScreenEdgesDeferringSystemGestures. This indicates to iOS that the next time a system gesture happens, it will need to call preferredScreenEdgesDeferringSystemGestures on the view controller to discover which edges apply.

The setNeedsUpdateOfScreenEdgesDeferringSystemGestures (as per the article I linked to) method was added in iOS 11, and since Delphi has a bit of catching up to do with iOS API changes, a bit of “hackery” was needed to call this method as can be seen by the declaration of UIViewControllerEx and TUIViewControllerEx, which essentially “extends” UIViewController.

The demo

I’ve created a demo that uses the patch for FMX.Platform.iOS and the DW.ScreenEdgeManager unit to demonstrate how this works, and the difference between when there’s no “preferred” edges and where they are. Instead of creating a patch file this time, I’m detailing the changes you need to make. Copy FMX.Platform.iOS from the Delphi source\fmx folder into the demo project folder, and:

Add DW.ScreenEdgeManager to the implementation uses clause

uses
  System.Classes, System.SysUtils, System.Types, System.UITypes, System.TypInfo, System.Messaging, System.RTLConsts,
  System.Math, Macapi.ObjCRuntime, Macapi.CoreFoundation, Macapi.Helpers, iOSapi.CocoaTypes, iOSapi.Foundation,
  iOSapi.CoreGraphics, iOSapi.Helpers, FMX.Graphics, FMX.Consts, FMX.Controls, FMX.Canvas.GPU, FMX.TextLayout,
  FMX.Text, FMX.Styles, FMX.Gestures, FMX.Context.GLES, FMX.Forms3D, FMX.Utils, FMX.Graphics.iOS, FMX.Context.GLES.iOS,
  FMX.Controls.iOS, FMX.Gestures.iOS, FMX.Helpers.iOS, FMX.Dialogs.iOS, FMX.Platform, FMX.Platform.Timer.iOS,
  FMX.Platform.SaveState.iOS, FMX.MultiTouch.iOS, FMX.Platform.Metrics.iOS, FMX.Platform.Device.iOS,
  FMX.Platform.Screen.iOS, FMX.Platform.Logger.iOS,
  DW.ScreenEdgeManager; // &lt;-------

Add the preferredScreenEdgesDeferringSystemGestures method to FMXViewController and TFMXViewController

  FMXViewController = interface(UIViewController)
    ['{FB1283E6-B1AB-419F-B331-160096B10C62}']
    // Some code snipped here
    function preferredScreenEdgesDeferringSystemGestures: UIRectEdge; cdecl; // &lt;------
  end;

  TFMXViewController = class(TOCLocal)
    // Some code snipped here
    function preferredScreenEdgesDeferringSystemGestures: UIRectEdge; cdecl; // &lt;------
  public

Add the implementation of TFMXViewController.preferredScreenEdgesDeferringSystemGestures

function TFMXViewController.preferredScreenEdgesDeferringSystemGestures: UIRectEdge;
const
  UIRectEdges: array[TScreenEdge] of UIRectEdge = (UIRectEdgeTop, UIRectEdgeLeft, UIRectEdgeBottom, UIRectEdgeRight);
var
  LScreenEdge: TScreenEdge;
begin
  Result := UIRectEdgeNone;
  for LScreenEdge := Low(TScreenEdge) to High(TScreenEdge) do
  begin
    if LScreenEdge in TScreenEdgeManager.PreferredScreenEdges then
      Result := Result or UIRectEdges[LScreenEdge];
  end;
end;

To see the effect of the changes, run the app on a device which (for example) has a “swipe” bar at the bottom, and tap and hold the button at the point where the swipe bar is. It might take a couple of tries, however you will notice that most of the time, there is a noticeable delay between when the button is tapped and the rectangle changes color. Now check the “Fix lag” checkbox and repeat the earlier steps. The rectangle changes color immediately, every time.

Introducing MonkeyBuilder

$
0
0

If you develop mobile apps for the app stores with Delphi, you’ll know that building and deploying a release is not a trivial task. MonkeyBuilder can reduce the time you spend from hours into just minutes!

Some MonkeyBuilder history

MonkeyBuilder is the brainchild of Graham Murt of Kernow Software. You may be familiar with his Pentire component library (formerly ksComponents), and his TksInputList component. He also has 3 mobile apps on the app stores, namely iFire, iRescue and iCrew. As you may have guessed, these are all emergency services related apps. Graham found he was spending a great deal of time in the build/deployment process, so he set about writing a tool that would allow him to automate the whole process.

During the development of MonkeyBuilder, Graham sought a way of retrieving certificate and provisioning profile information from the Mac, and asked about it on the Delphi Worlds Slack channels. Fortunately, I had already developed a means of doing just that in Mosco: an app that runs on the Mac that other apps can connect to and query information like certificates and profiles. So now a partnership has been born between myself and Graham to deliver MonkeyBuilder.

MonkeyBuilder is presently in beta

The first release of MonkeyBuilder is just around the corner, and to help us along we are calling for beta testers, so if you are interested, please use the contact form to let us know.

Visit the MonkeyBuilder website

The MonkeyBuilder website is also still under construction, however it has a couple of screenshots, a demo video (on the screenshots page), and the proposed pricing is also there, so please check it out.

It’s time to Get Excited!

$
0
0

The release of Delphi 10.4 Sydney is just around the corner. I’ve specifically been given permission to show updates and new features in the product, so let’s get to it..

Note: This is pre-release information

As such, any or all of it may change. Please check the What’s New when the product is officially released.

API enhancements and fixes

One of the things you may notice is that there have been fixes to existing APIs on macOS, and additions to APIs on macOS and iOS. In particular, there’s been a number of methods added to imports of Objective-C classes that developers have been asking for, such as for NSNotificationCenter and NSObject.

In Delphi 10.4 Sydney, the dependence on QTKit has now been totally removed – no more annoying warnings when uploading to the macOS App Store, and a couple of issues regarding permissions have now been solved.

Improvements to existing components

The implementation for TWebBrowser on macOS and iOS has now been migrated to use WKWebView. This means it now supports playing mp4 files from web pages that are navigated to, and there should be no more warnings when you upload your app to the store.

There are also improvements to TLocationSensor for iOS. 3 new properties have been added (all related to iOS only), namely:

  • ActivityType – this property corresponds the to the activityType property for CLLocationManager on iOS
  • UsageAuthorization – now you can specify what kind of usage is requested when starting TLocationSensor, i.e. Always and WhenInUse
  • OnLocationUpdatesPausedChange event – this notifies when location updates “paused” state has changed.

Also, you should now find that location updates occur when the app is in the background, or when the app is not running, as long as you include location in UIBackgroundModes in the Project Options.

..and much, much more!

The above mentioned changes are just some of many. Please check the blogs of other MVPs, and product managers like Marco Cantu, Sarina Du Pont and David Millington, for more news about Delphi 10.4 Sydney.

Introducing Kastri

$
0
0

Coinciding with the release of Delphi 10.4 Sydney, commercialization of Kastri has morphed into using Github Sponsors to help fund its development. This article details whats changed, whats new, and the future of Kastri.

Kastri Free

Be assured the Kastri Free repo will remain, however all new development will continue in the new Kastri repo.

Github Sponsors

There are 3 tiers of monthly sponsorship and any tier will help support and guarantee the future development of Kastri as well as contribute to enhancing the product as technology changes. All sponsors will have exclusive access to the #sponsors channel in the Delphi Worlds Slack Team where they can participate in making feature suggestions, highlight enhancements and best practices for how they use Kastri and other Delphi Worlds libraries in their development.

 Tier 1 – $5.00

Every developer knows that coding is fuelled by coffee. This level gives you the satisfaction of knowing you’re supporting Kastri and other repos, and allows us to stock the coffee machine. (Please note on Fridays this may go towards beer or a nice red.)

Tier 2 – $20.00

Aimed at those lone developers slaving away on their keyboards and use Kastri or any other repo for commercial purposes. Ideally you’ll have less than 100 users across your products.  Included at this level are 2 priority support incidents* per year.

Tier 3 – $50.00

Choose this tier if you are using my libraries or components in commercial applications and they provide a significant asset among your tools as a developer or organisation. At this level you receive 4 support incidents* per year

*Support incidents are related to the Kastri repo only. Details of how support incidents will be handled are being finalised.

Click Here to start sponsorship of Delphi Worlds

Supported Delphi Versions

Supporting older versions can be time consuming, however more importantly: Kastri revolves mostly around mobile development, and if you’re deploying to the app stores, staying current is essential. Kastri will now support Delphi 10.3 and above only

The New Repo

If you visit the new repo, you’ll find there has been a number of changes from Kastri Free.

  • New API import files – including some that will be used in upcoming features
  • Renamed/rationalized API import files – some imports have been aggregated, and some have had the file renamed to better reflect what is in it
  • ComponentHelpers (which really should have been named Interposers) has been removed and the files moved into Core
  • Some of the Demos that were in Kastri Free have not been migrated, because they’re not relevant to Kastri requirements, and some have been revamped (or will be)
  • New Features have been added, namely: Biometrics (TouchID/FaceID on iOS and Fingerprint support on Android), and Speech Recognition.
  • Files in the Java and ThirdParty folders have been reorganized
  • A new folder called Tools that will contain executables used for build automation etc.

Upcoming Features

New features are coming to Kastri, and your sponsorship will help make them a reality sooner. They include:

  • Photos library support – a platform agnostic means of managing collections of photos stored on the device, and a Facebook-style photos selector
  • Apple Login – implementation of Apple Login that adheres to the App Store guidelines
  • Universal Links – support for custom schemes and universal links on iOS
  • Camera – a revamp of the original Delphi Worlds Camera project, with support for iOS and Android

Delphi 10.4 Sydney

Kastri has already been tested with Delphi 10.4 Sydney, and is fully compatible.

Sponsor Today!

Click Here to start sponsorship of Delphi Worlds to ensure the future development of Kastri as well as contribute to enhancing the product as technology changes.

Codex 1.3, and other stuff in the works

$
0
0

If you follow the Codex repo, you would have noticed that version 1.3 was actually uploaded a couple of days ago. This article describes a what’s new and changed in Codex, and things I’m working on for Kastri.

Codex

Editor Tabs On Left

With the release of Delphi 10.4 Sydney came some changes to the IDE, which includes the StatusBar at the bottom of the code editor windows. Those changes in particular broke the “Editor Tabs On Left” feature of Codex. I struggled for a while to make them work again, however the best I could do so far is to have them appear on the left only if the macro toolbar that appears in the extreme left is hidden, and even then when the desktop changes (such as when debugging) it would all fall apart again, so I have shelved that feature in 10.4 for now.

ADB Connect

Codex 1.3 has a new feature: ADB Connect. This allows you to connect to an Android device over a network, as long as your machine can “see” the other address. The option is available via Tools|Codex|ADB Connect, or via the new Codex toolbar that you can enable by right-clicking the Delphi main toolbar and checking the Codex item:

In order to connect to a device via IP, first the device needs to be connected to a machine via a USB cable, then at a command prompt, run this command:

[path_to_adb]\adb tcpip 5555

Where [path_to_adb] is the path to the adb command on the machine, which means it will need to have at least the Android SDK tools installed (i.e not necessarily the whole SDK). This is all made simple via DeviceLens, which can help with installing the Android SDK tools, and actually run the command required to put the device into TCPIP mode:

Once the device is in TCPIP mode, you can use the ADB Connect feature to connect to the device:

The “configure for TCPIP” part could appear in a future version of Codex. ADB Connect was developed in response to being able to debug/monitor a device over a VPN, so the device may not even be in the same country as the machine that has Codex on it.

Total Clean

A menu item has been added to the Project Manager context menu called Total Clean:

This option will remove all files in the projects output folders for every platform as well as the folders themselves (if it can), so please use it when you’re absolutely sure that’s what you want to do.

In the works for Kastri

As per the last article, there are a number of things planned for Kastri. Becoming a Github Sponsor will help make these a reality. I’m currently working on:

Apple Signin support

As per Apple’s guidelines, if you offer login via any of the major social media providers, you must also offer login via Apple Signin (this has applied since April 2020). I have an implementation in testing phase, so if you’re interested in helping out, please join my Slack team and go to the #kastri channel.

Camera for Mobile

A while ago I published this project, which implements the device camera using the newer Camera2 API on Android. I had plans to add iOS support when I started it, and actually had a private project that did implement it on iOS, however I shelved all of it due to time constraints. When joining Github Sponsors, I figured I should include features that would help encourage developers to sign up for sponsorship, so I have resurrected the camera project to be part of Kastri.

Some of the work has been done, including having the camera preview take advantage of the native view implementation included in Delphi so that it has z-order support, e.g. you can have the preview on a tab of a tab control, and switch tabs without having to turn off the preview. Also, because it uses native classes for the preview, performance is way above that of the built-in camera component in Delphi

Other items in the works

These items are planned:

  • Photos library that makes use of the Photos framework on iOS, and has implementation for Android
  • Universal Links support on iOS
  • Background Task management for iOS
  • Background Fetch for iOS (improved version)
  • Sensors (using the OS APIs)

All items currently in the works or planned have a much better chance of becoming a reality and potentially sooner with sponsorship, so please consider becoming a sponsor today!

 

Viewing all 80 articles
Browse latest View live