[fpc-pascal] String concatenation failure (again)

Jürgen Hestermann juergen.hestermann at gmx.de
Tue Aug 2 16:51:20 CEST 2016

Am 2016-08-02 um 12:25 schrieb Jürgen Hestermann:
 > ------------------------------------------
 > type MyStringType = string;
 > var S     : MyStringType;
 >     Liste : array of MyStringType;
 >     i     : SizeInt;
 > begin
 > [..] // "Liste" is setup with many string entries (which are also shown correctly with Ctrl+F7 (evaluate/modify)
 > S := '';
 > for i := Low(Liste) to High(Liste) do
 >    S := S+Liste[i]+LineEnding;
 > SetLength(Liste,0);
 > ShowMessage(S);
 > end;
 > ------------------------------------------

I just tested a bit more and it seems that the problem
is located in the way the strings are fed into "Liste"
which is done like this from a Windows API function:

if FindNextFileNameW(H,Laenge, at Pfad[1]) then
    Liste[High(Liste)] := copy(Pfad,1,Laenge);

where "Pfad" is a "widestring" (because of the Windows W-function),
"H" is of type "hwnd" and "Laenge" is "SizeInt".

I would expect that with the new string encoding handling
widestring will be converted automatically to "MyStringType"
(which is string in my case). This assumption is  encouraged
by the fact that "Liste" is shown with the correct list of all strings
in the evaluate window when debugging.

The interesting thing is, that *one* (the first) string
from "Liste" is added to "S" (but all others are missing).

More information about the fpc-pascal mailing list