You are not logged in.
I have detected an unexpected behavior on old Delphi compiler vs. newer one.
var s:string;
dynArr:TRawUtf8DynArray;
begin
s := 'test1';
setLength(dynArr,1);
dynArr[0]='test1';
Result := DynArray(TypeInfo(TRawUtf8DynArray),dynArr).IndexOf(s,true);
end;
-> Delphi7: Result=0, found
-> Delphi12: Result=-1, not found
If i cast the string to RawUtf8 or use RawUtf8 directly it is working.
var u:RawUtf8;
dynArr:TRawUtf8DynArray;
begin
u := 'test1';
setLength(dynArr,1);
dynArr[0]='test1';
Result := DynArray(TypeInfo(TRawUtf8DynArray),dynArr).IndexOf(u,true);
end;
-> Delphi7: Result=0, found
-> Delphi12: Result=0, found
Offline
It's expected behavior.
String type is AnsiString in Delphi 7 and UnicodeString in Delphi 12, but RawUtf8 is AnsiString(65001) in both.
So, code in first example is wrong. DynArray.IndexOf parameter must be of the same exact type as the dynamic array element - i.e. RawUtf8.
Last edited by Chaa (2024-09-16 09:50:41)
Offline
Hi Chaa,
thank you for the clarification. I was already thinking something like that. Due to the code base that is used by Delphi 7 and Delphi 12, many things have not yet been converted to RawUTF8. So we must must be careful in various places. Some of the framework's operations also work with the D7:string without any problems.
Offline