我在Delphi XE8方面很新。我有以下代码来自我的Delphi 6版本,我想在Delphi XE8中运行它。
1. function UTF8ToStringLen(const src: PChar; const Len: Cardinal): widestring;
2. var
3. l: Integer;
4. begin
5. SetLength(Result, Len);
6. if Len > 0 then
7. begin
8. l := MultiByteToWideChar( CP_UTF8, 0, src, Len, PWChar(Result), Len*SizeOf(WideChar)); <--error
9. SetLength(Result, l);
10. end;
11. end;
12.
13.
14. function StringToUTF8Len(const src: PChar; const Len: Cardinal): string;
15. var
16. bsiz: Integer;
17. Temp: string;
18. begin
19. bsiz := Len * 3;
20. SetLength(Temp, bsiz);
21. if bsiz > 0 then
22. begin
23. StringToWideChar(src, PWideChar(Temp), bsiz);
24. SetLength(Result, bsiz);
25. bsiz := WideCharToMultiByte(CP_UTF8, 0, PWideChar(Temp), -1, PChar(Result), bsiz, nil, nil); <--error
26. if bsiz > 0 then dec(bsiz);
27. SetLength(Result, bsiz);
28. end;
29. end;
当我试图运行代码时,出错信息指向代码的第8行和第25行,并显示一个错误消息。
ERROR MESSAGE: Incompatible types: 'PAnsiChar' and 'PWideChar'
我已经到处寻找解决方案,但是我无法解决这个问题。请帮忙...谢谢。