Wednesday, 12 February 2020

The Enter key and the OnKeyDown/OnKeyUp events on Android

A problem surfaced on Stack Overflow recently from a Delphi developer, Tom Byrnes, who discovered that on Android, the Enter (or Return) key no longer triggers the OnKeyDown and OnKeyUp events. This was unfortunate as Tom wanted to code to run in (one of) those handlers.

The problem had been reported as RSP-27496 but alas it had been closed at the time Tom was hunting for a solution (to my mind closed wrongly).

What to do?

Well, after some valiant fighting with the problem accompanied with the inevitable wailing and gnashing of teeth, Tom found a workaround of sorts. Setting the TEdit control's ReturnKeyType property Go, Search or Send allows the OnKeyDown event to fire for the Enter key. Good stuff! But not ideal....

I sent a note to a relevant party within EMBT and after reviewing the report it has since been re-opened. That's a start.

Tuesday, 11 February 2020

C++Builder's Android location sensor woes

There is an unfortunate problem with RAD Studio 10.3.3 for anyone using C++Builder building Android applications. However it has a quite straightforward resolution, so let's look at what the issue is.

If you make a new Multi-Device Application in C++Builder and build it, all will be well, of course. The basics work very nicely.

If you now drop a TLocationSensor component on the form and try to build now, the result will be different. Compilation goes fine. Linking looks like it is going fine.... until it fails with a rather unhelpful message:

[ldandroid Error] "ld" exited with code 1.

Let's look at how we can get more useful feedback from this rather opaque and somewhat 1990s error message and see how to resolve the underlying problem.

Rebuilding the Delphi & C++Builder Android Java files

Some while back I posted a command script (or batch file as we used to call them) that could be used by RAD Studio 10.3 users if they felt the need to change any of the few Java files underlying Delphi's (and C++Builder's) Android RTL and FireMonkey code.

The script would rebuild all the Java files into the required fmx.dex.jar and fmx.jar archives and copy them into the relevant RAD Studio installation folders to be used on subsequent builds.

When I tried to use the script with RAD Studio 10.3.3 of course it didn't work as things have changed, different files need to be involved in the process. I have updated the script now to work with RAD Studio 10.3.3 and thought I'd share it in case anyone else needs to do this.

An obvious question is: Why would anyone else want to rebuild the Java Android RTL files? Well this is normally a necessary step if you find an issue in the code as Embarcadero ships it and you want to try to fix it or enhance it. Indeed the previous post on rebuilding the 10.3 Java files was all about patching the Java code to get Android Intent support working.

If you have no interest in tweaking the Java code or fixing any issues you encounter in the Java code then you probably won't be needing this script.

If you do need the script, remember to take a backup of your original compiled archives before you proceed. These are found in:

  • C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\debug\fmx.jar
  • C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\debug\fmx.dex.jar
  • C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\release\fmx.jar
  • C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\release\fmx.dex.jar

The script needs to be run from an administrative command prompt and before you run it you should double-check the various paths set up in the environment variables at the start are all valid on your system.

Tuesday, 8 January 2019

Solution to iOS Delphi build failure

Some Delphi users building iOS applications have been thwarted by a…, well let’s be polite and call it a bit of an annoyance, when building their applications. What should just be an informational message about a warning from the ld linker ends up becoming a build breaker. The failure message looks something like this example (taken from RSP-19759, reported in January 2018):

[DCC Error] E2597 ld: warning: unknown dwarf DW_FORM_strp (offset=0xFFFFCEE7) is
too big in FBSDKShareKit.a(FBSDKAppInviteContent.o) ld: warning: unknown dwarf DW_FORM_strp (offset=0xFFFF6E38) is too big
in C:\Dev\lib\ios\facebook\FBSDKShareKit.framework\FBSDKShareKit.a
(FBSDKAppInviteContent.o)

The fact that ld is emitting a warning about something is neither here not there. Or rather it *should* be neither here nor there. Unfortunately when Delphi receives this warning it turns it into a fatal error.

Oh dear… (・_・、)

Delphi 10.3 Rio contains a change to address this issue…. ˚◡˚

Unfortunately, however, Embarcadero forgot to mention it to anyone ¯\_(ツ)_/¯

This post tries to fix that communications oversight by covering the details of the change, which is an important step as you do need to add in a new compiler / linker switch.

The iOS ld linker now supports a new option –bequiet, which stops Delphi being able to wrongly interpret the ld warnings (by silencing them).

To use the new option choose Project | Options…  (Shift+Ctrl+F11) and do one of these two things:

  • select Building | Delphi Compiler | Compiling | Other Options and add --linker-option:-bequiet to Additional options to pass to the compiler, or
  • select Building | Delphi Compiler | Linking and add -bequiet to Options passed to the LD linker

You should now be able to build your project successfully without this little hindrance.

Good luck!

Saturday, 8 December 2018

CodeRage 2018 (redux)

This year at CodeRage 2018 I presented a session on Creative Delphi Debugging Techniques.

Other than my speaking volume being a bit quiet, it generated a number of very nice comments about the subjects covered so I thought it might be useful to mention that it is available for on-demand viewing as part of the CodeRage 2018 Replay.

There is free enrolment in the conference replay and my session, along with the session slides and sample files, can be found here.

If you watch it I hope you turn up your PC volume and get a lot out of it to hopefully help with your debugging exercises!

RAD Studio 10.3 Rio’s Android Intent support (or current lack thereof)

Sometimes when a new product is released there are a few ‘teething issues’. That certainly seems to be the case with RAD Studio 10.3 Rio. Both Delphi and C++Builder are hitting a few problems on various fronts. Now, it is true that internally in the product there has been a lot of change in the IDE, the VCL and FireMonkey, and perhaps it is therefore unsurprising a few slip-ups will have occurred.

It is, however, quite annoying when you fall foul of these slip-ups and have to wait for a fix….

The issue I want to address in this post is the breakage in the Android support for registering an interest in knowing about certain Intent objects received by the app. This is normally achieved by a call to MainActivity.registerIntentAction, as pseudo-documented here (when it was introduced in RAD Studio 10 Seattle) and here (in reference to a sample app) on Embarcadero's docwiki and illustrated here in my article on NFC usage.

This new Intent support worked nicely in RAD Studio 10 Seattle, 10.1 Berlin and 10.2 Tokyo. Not so in RAD Studio 10.3 Rio. You get a crash when trying to register a new Intent that you want to act upon.

Sunday, 2 December 2018

CodeRage 2018

Just when I thought conference season was over, CodeRage 2018 came rapidly into view!

I like CodeRage – there’s always a good range of session subjects to choose from, and alwyas a range of good speakers to listen to.

I’ve had sessions at a few CodeRage conferences over the years, CodeRage 7, CodeRage 8, CodeRage XI and CodeRage XII. I’m pleased to continue that trend with a session at CodeRage 2018 – the official web page is at https://www.embarcadero.com/coderage-2018 and the registration page is at http://forms.embarcadero.com/CodeRageRegistration18.

This year I’m presenting my session on Creative Delphi Debugging Techniques. This session has been received positively when I’ve presented a trimmed down version of it to audiences at various conferences around Europe so I thought it would be an ideal session to present in full at CodeRage 2018 and have it available online ongoing.

I’ll be online on Wednesday 5th December at 5pm CST (UTC-6), which is 11pm GMT and the session will last 90 minutes (an hour and a half!). If you can stop by my session I’d really appreciate it, and hopefully you’ll pick up a few tips about some of the Delphi debugger features and possibly lose some of the fear of the CPU window… (yes, we’ll be spending some time in the CPU window!).

Have a fantastic CodeRage 2018!