Fixes#7690.
When kmshell.dpr is being shut down by Windows via `WM_ENDSESSION`, the
order of termination of units through `finalization` sections means that
`IdStackWindows` was finalizing while components were still depending on
it, causing a cascade of exceptions resulting eventually in the crash
visible in #7690.
We saw this when there were message loops before `Application.Run` had
ever been called. For example, message box/dialog, ShellExecute (yep...
this can do a `PeekMessage`), `THttpUploader` (which calls
`Application.ProcessMessages`) and probably others.
Ideally, it would be better to always call `Application.Run`, but it is
not safe to call `Application.Run` more than once, because it ends up
adding multiple `DoneApplication` exit procs, which would likely cause
other crashes.
I landed on the somewhat heavy-handed solution of adding
`IdStackWindows` to the start of the project `uses` list, ensuring it is
the last unit to be finalized -- importantly, before `Vcl.Forms`. A
better solution would be to find a way of ensuring that
`Application.Run` is called, just once, in all situations, but this is
likely to be hard to achieve. The shutdown sequence for Delphi apps is
so very, very fragile.
Relates to KEYMAN-WINDOWS-B.
While this doesn't address the root cause of the exception, it should
prevent this unhandled exception, and adds breadcrumbs to help us see
which code path might be triggering the issue.
While Keyman Core already supported the base layout flags, they were not
being passed in from Keyman Engine for Windows. This meant that any
rules that used `baselayout` would fail, such as in sil_ipa with AltGr+0
for }
0bf72bed74/release/sil/sil_ipa/source/sil_ipa.kmn (L348-L350)
This patch adds support for the following properties:
* KM_KBP_KMX_ENV_BASELAYOUT: the legacy base layout name, e.g. kbdus.dll
* KM_KBP_KMX_ENV_BASELAYOUTALT: the BCP 47 base layout name, e.g. en-US
* KM_KBP_KMX_ENV_SIMULATEALTGR: whether the user has selected to emulate
AltGr with Ctrl+Alt, for example on laptops without a right alt key.
* KM_KBP_KMX_ENV_BASELAYOUTGIVESCTRLRALTFORRALT: whether the system base
layout in use generates Ctrl+RAlt when RAlt is pressed, which can be
true for many European system layouts. This is necessary when
associating the keyboard with a European language because the base
keyboard becomes the language's default keyboard, rather than kbdus.