Convert string to PAnsiChar in Delphi 2009

后端 未结 6 659
灰色年华
灰色年华 2021-02-01 17:50

I\'m converting my applications to Delphi 2009 and faced an intriguing issue with some calls that need to convert a string (wide) to AnsiString.

Here\'s an example to de

6条回答
  •  青春惊慌失措
    2021-02-01 18:34

    I have no Delphi 2009 here, so I can't check it. But maybe you have to try:

    s := PAnsiChar(AnsiString(Application.ExeName));
    

    As gabr already pointed, this is not a very good practice, and you will only use it if you are 100% sure. The string only contains characters that have a direct mapping to the ANSI range.

    That's why you should get a warning because you are converting Unicode to ANSI.

提交回复
热议问题