The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,573 other followers

Archive for the ‘Delphi’ Category

Some uptime monitoring tools that are still free and understand more than http/https

Posted by jpluimers on 2022/01/19

Since uptimerobot has slowly moving free features, part of my family uses it to monitor uptime of their personal stuff, and I don’t want to pay for the free monitoring I do on Embarcadero infrastructure (I know that they have been phasing out older useful sites for ages, but even their main sites were down for 2 days about a year ago).

Yes, I know the competitiveness of [Wayback] Website monitoring – Wikipedia, and I’m glad Uptimerobot has been there for a relatively long time, but alas: for personal use…

The list of of the pricing pages of each site, containing a one line summary blurb if it was available:

Via [Wayback] 16 Best Online Services to Monitor Sites Uptime

Related: [Wayback] EmbarcaderoMonitoring: www http


Posted in *nix, Delphi, Development, Monitoring, Power User, Software Development | Leave a Comment »

Delphi SetRoundMode: gets sets part of the 8087 control word (related: GetRoundMode and TFPURoundingMode)

Posted by jpluimers on 2022/01/12

I thought I had written about this a long time ago, as Math.SetRoundMode (and now System.Math.SetRoundMode) has been introduced since at least Delphi 2007. There are also related GetRoundMode and TFPURoundingMode.

Delphi 2009 also introduced TFPUPrecisionMode, GetPrecisionMode and SetPrecisionMode.

Delphi 2010 also introduced TFPUException, TFPUExceptionMask, TFPUPrecisionMode, TFPURoundingMode, ClearExceptions, GetExceptionMask, and SetExceptionMask.

Delphi XE2 introduced namespaces, so prepended the unit Math with the namespace System. to become unit System.Math. It also introduced $EXCESSPRECISION (for x64), GetMXCSR, SetMXCSR, ResetMXCSRClearFPUExceptionsTSSEException, TSSEExceptionMask, GetSSEExceptionMask, SetSSEExceptionMask, ClearSSEExceptions, TSSERoundingMode, GetSSERoundMode, SetSSERoundMode.

The documentation basically only had formatting changes. This is the most important part of SetRoundMode:

function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;

Call SetRoundingMode to specify how the FPU handles rounding issues. The rounding mode can be any of the following values:

Rounds to the closest value.
Rounds toward negative infinity.
Rounds toward positive infinity.
Truncates the value, rounding positive numbers down and negative numbers up.

This is the most important bit of SetPrecisionMode:

function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;

Call SetPrecisionMode to specify the level of precision that the FPU (floating-point unit) uses for floating-point calculations. The precision control mode can be any of the following values:

single precision
not used
double precision
extended precision

SetPrecisionMode returns the previous precision control mode.

Both are functions, so so they return the previous value which you can use to set it back later: this is important as it is a process wide. SetPrecisionMode documents this, but SetRoundMode does not!

Global side effects and avoiding them

Since SetRoundMode and SetPrecisionMode set the 8087 CW (and on XE2 and up SetMXCSR), it means all usual Set8087CW caveats apply: changing the global 8087 CW setting impacts all running code, which means that threads, DLLs (especially ones written in other languages), etc might malfunction. You can find some of the caveat effects on my bog by searching for [Wayback] Set8087CW – Google Search.

If you want to avoid global side effects, you might try the solution in [Wayback] c# – What is the equivalent of Math.Round() with MidpointRounding.AwayFromZero in Delphi? – Stack Overflow by [Wayback] Andreas Rejbrand.


[Wayback/] SSE Instruction Set (not sure why Embarcadero used this as reference material from their docwiki, but hey, Intel documentation is likely outdated):


The MXCSR register is a 32-bit register containing flags for control and status information regarding SSE instructions. As of SSE3, only bits 0-15 have been defined.

Pnemonic Bit Location Description
FZ bit 15 Flush To Zero
R+ bit 14 Round Positive
R- bit 13 Round Negative
RZ bits 13 and 14 Round To Zero
RN bits 13 and 14 are 0 Round To Nearest
PM bit 12 Precision Mask
UM bit 11 Underflow Mask
OM bit 10 Overflow Mask
ZM bit 9 Divide By Zero Mask
DM bit 8 Denormal Mask
IM bit 7 Invalid Operation Mask
DAZ bit 6 Denormals Are Zero
PE bit 5 Precision Flag
UE bit 4 Underflow Flag
OE bit 3 Overflow Flag
ZE bit 2 Divide By Zero Flag
DE bit 1 Denormal Flag
IE bit 0 Invalid Operation Flag

FZ mode causes all underflowing operations to simply go to zero. This saves some processing time, but loses precision.

The R+R-RN, and RZ rounding modes determine how the lowest bit is generated. Normally, RN is used.

PMUMMMZMDM, and IM are masks that tell the processor to ignore the exceptions that happen, if they do. This keeps the program from having to deal with problems, but might cause invalid results.

DAZ tells the CPU to force all Denormals to zero. A Denormal is a number that is so small that FPU can’t renormalize it due to limited exponent ranges. They’re just like normal numbers, but they take considerably longer to process. Note that not all processors support DAZ.

PEUEMEZEDE, and IE are the exception flags that are set if they happen, and aren’t unmasked. Programs can check these to see if something interesting happened. These bits are “sticky”, which means that once they’re set, they stay set forever until the program clears them. This means that the indicated exception could have happened several operations ago, but nobody bothered to clear it.

DAZ wasn’t available in the first version of SSE. Since setting a reserved bit in MXCSR causes a general protection fault, we need to be able to check the availability of this feature without causing problems. To do this, one needs to set up a 512-byte area of memory to save the SSE state to, using fxsave, and then one needs to inspect bytes 28 through 31 for the MXCSR_MASK value. If bit 6 is set, DAZ is supported, otherwise, it isn’t.

Architectures Software Developer’s Manual: Intel® 64 and IA-32 includes supporting processors programming environment and architecture.

[Wayback] Intel® 64 and IA-32 Architectures Developer’s Manual: Vol. 1


Documentation links

Some of the documentation links (that regrettably do not explain what happens behind the scenes with the 8087 CW) are these:



Posted in Delphi, Development, Software Development | Leave a Comment »

When MySQL characterset ‘utf’ does not allow you to enter some Unicode code points

Posted by jpluimers on 2022/01/06

Contrary to what many believe is that MySQL utf8 is not always full blown UTF-8 support, but actually utf8mb3, which has been deprecated for a while now.

Only utf8mb4 will give you full blown UTF-8 support.

This when someone reminded me of this in a Delphi application:

When I insert :joy: emoji into mysql varchar filed I got an error :
#22007 Incorrect string value: '\xF0\x9F\x98\x82' for column 'remarks' at row 1

database charset is utf8

Note that the :joy: emoji is 😂 and has Unicode code point U+1F602 which is outside the basic multilingual plane.



Posted in Conference Topics, Conferences, Database Development, Delphi, Development, Encoding, Event, MySQL, Software Development, UTF-8, UTF8 | Leave a Comment »

Delphi design-time packages: “%1 is not a valid Win32 application”

Posted by jpluimers on 2021/12/22

For my link archive, as I hardly see this (it happens in many Delphi versions and always has to do with missing/wrong DLLs), so always forget how to solve it.

Basically it is the same fix as for Fixing hg.exe “ImportError: DLL load failed: %1 is not a valid Win32 application.”:

If you get the below error when running hg.exe, then you are mixing a 64-bit Mercurial with 32-bit dependencies.

[Wayback] XE2 – “%1 is not a valid Win32 application” when installing a package – embarcadero.delphi.ide with entries by [Wayback] Remy Lebeau and [Wayback] Jeff Overcash:

I don't know what I did, but when trying to install a set of freshly built 
Delphi Win32 packages into the IDE, XE2 is giving me this error message now:

Can't load package ...
%1 is not a valid Win32 application.


> Often that is caused by the same named 32 and 64 bit run time packages
> and the OS finding the 64 bit first when the IDE must load the 32 bit.  If
> that is the case check your path variable and make sure the 32 bit paths
> appear first.

That was the problem.  The Windows PATH variable had a 64-bit folder in front 
of the 32-bit folder.  Deleted the 64-bit files and the error went away. 
 Noe I'm getting a new error:

The program can't start because <RuntimePackage>.bpl is missing from
your computer. Try reinstalling the program to fix this problem.

But the "missing" package is in the same folder as the design-time package 
I am trying to install.

Since the design time location is known it is explicitely 
loaded, but the run time is implicitly loaded and follows the dll loading rules. 
  Both are dynamically loaded.

The reason you only see this the next time you restart the IDE is because the 
working directory changes to your project directory when you load a project so 
if the runtime is there it is found that way, but the next time you load the IDE 
the working directory starts in the bin directory.

I thought it was, but turns out the 32-bit output folder had been moved and 
the PATH was not updated accordingly.  Fixed the PATH and now the packages 


Posted in Delphi, Development, Software Development | Leave a Comment »

Delphi MVVM links

Posted by jpluimers on 2021/12/16

After I did conference presentations and wrote a magazine article and in 2013 about Delphi MVVM using DSharp, I saw a 3 articles in 2018, then I went through a big rollercoaster involving rectum cancer treatment.

After recovering, I found that there is one commercially project working on an MVVM framework implementation.

So here are some links on MVVM from new to old:

In my experience experimenting with MVVM and other three- and four-letter frameworks, I found a recurring concept is “convention over configuration”. This relies heavily on having matching names in the various layers.

There you see a big drawback in the Delphi compiler: it lacks a NameOf expression, which means a lot of literal strings ending in your code. Few of the MVVM frameworks have good logging explaining when literals mismatch.

The C# compiler also took a while (until C# version 6 in 2015) to get one, but now supports the [Wayback] nameof expression – C# reference | Microsoft Docs. Some more documentation about this:

Furthermore, the Delphi compiler lacks helpers on interfaces and helpers for generics (heck, I would actually want full extension methods) and generic parameters for methods on interfaces (which is different from the generic parameters on the interface declaration itself). This lack of these features often cause for convoluted syntax to workaround this. Stefan explains the first lacks more clearly in [Wayback] Delphi sorcery: Why no extension methods in Delphi?.

Requests for the nameof expression and interface helpers have been there since at least 2015:


Posted in Delphi, Development, Software Development, Spring4D | Leave a Comment »

%d bloggers like this: