I have the following variable declarations:
arrChar_1: array[0..2] of Char;
arrChar_2: array[0..2] of Char;
str: string;
Then I made the assignment:
str := arrChar_1 + arrChar_2;
This assignment works normally on Delphi 6. But error occurs when I compile it on Delphi 10.2:
[dcc32 Error] MigrateConcatenateCharArray.dpr(26): E2008 Incompatible types
I'm solving this problem in the following way:
str := Copy(first_arrChar, 0, StrLen(first_arrChar));
str := str + Copy(second_arrChar, 0, StrLen(second_arrChar));
Is there any other good solution to this problem? (1)
In Delphi 6:
String = AnsiString
Char = AnsiChar
In Delphi 10.2:
String = UnicodeString
Char = WideChar
Can tell me what caused the incompatibility issue to occur? (2)
I'm understanding that widechar is a multi-byte character type. Unicode is the way that characters are encoded. But I'm confused about them.
str := string(arrChar_1) + string(arrChar_2);
or worst casestr := string(@arrChar_1[0]) + string(@arrChar_2[1]);
But, just for performance reasons, I would probably uselen1 := StrLen(arrChar_1); len2 := StrLen(arrChar_2); SetLength(str, len1 + len2); Move(arrChar_1, PChar(str)^, len1 * sizeof(Char)); Move(arrChar_2, (PChar(str) + len1)^, len2 * sizeof(Char));
or evenstr := Format('%s%s', [arrChar_1, arrChar_2]);
– Welfordstr := string(arrChar_1) + string(arrChar_2);
? – Lauxstr := arrChar_1; str := str + arrChar_2;
. It seems to be a compiler error and should be reported at QP. – Marra