I have a question about a specific programming problem in Delphi 10.2 Pascal programming language.
The StringOfChar and FillChar don’t work properly under Win64 Release build on CPUs released before year 2012.
Expected result of FillChar is just plain sequence of just repeating 8-bit characters in a given memory buffer.
Expected result of StringOfChar is the same, but the result is stored inside a string type.
But, in fact, when I compile our applications that worked in Delphi prior to 10.2 by the 10.2 version of Delphi, our applications compiled for Win64 stop working properly on CPUs released before year 2012.
The StringOfChar and FillChar don’t work properly – they return a string of different characters, although in a repeating pattern – not just a sequence of the same character as they should.
Here is the minimal code enough to demonstrate the issue. Please note that the length of the sequence should be at least 16 characters, and the character should not be nul (#0). The code is below:
procedure TestStringOfChar;
var
a: AnsiString;
ac: AnsiChar;
begin
ac := #1;
a := StringOfChar(ac, 43);
if a <> #1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1 then
begin
raise Exception.Create('ANSI StringOfChar Failed!!');
end;
end;
I know that there are lots of Delphi programmers at StackOverflow. Are you experiencing the same problem? If yes, how you resolve it? What is the solution? By the way, I have contacted the developers of Delphi but they didn’t confirm nor deny the issue so far. I'm using Embarcadero Delphi 10.2 Version 25.0.26309.314.
Update:
If your CPU is manufactured in 2012 or later, additionally include the following lines before calling StringOfChar to reproduce the issue:
const
ERMSBBit = 1 shl 9; //$0200
begin
CPUIDTable[7].EBX := CPUIDTable[7].EBX and not ERMSBBit;
As about the April 2017 RAD Studio 10.2 Hotfix for Toolchain Issues - have tried with it and without it - it didn't help. The issue exists regardless of the Hotfix.
Update #2
Embarcadero has confirmed and resolved this issue on 08/Aug/17 6:03 PM. So, in Delphi 10.2 Tokyo Release 1 (released on August 8, 2017) this bug is fixed.