Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3595660
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:52:54+00:00 2026-05-18T19:52:54+00:00

The situation: I’ve an external DLL that uses UTF-8 as its internal string format.

  • 0

The situation: I’ve an external DLL that uses UTF-8 as its internal string format. The interface functions all use PAnsiChar to pass strings along.

The rest of my application uses Delphi’s native string type; since I’m working with Delphi 2010, that will map to a UnicodeString.

How can I reliably cast those PAnsiChar arguments (which are pointing to UTF-8 encoded strings) to a UnicodeString?

I had this function, which I thought worked fine:

function PUTF8CharToString(Text: PAnsiChar): string;
var
  UText: UTF8String;
begin
  UText := UTF8String(Text);
  Result := string(UText);
end;

…but now I’ve run into a case where the result string is corrupted; when I save the PAnsiChar to file, it’s fine; but when I save the resulting string after conversion using the above function, it’s corrupted.

Or should this work correctly, and is this indicative of some other memory (de)allocation problem?


Edit: I finally managed to get rid of the memory corruption by assigning the converted string to a local variable string, instead of directly passing it to another function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T19:52:55+00:00Added an answer on May 18, 2026 at 7:52 pm

    From System:

    function UTF8ToUnicodeString(const S: PAnsiChar): UnicodeString; overload;


    UnicodeStr := System.Utf8ToUnicodeString(Text);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The situation: I’ve an external DLL that uses UTF-8 as its internal string format.
Here's my situation: I'm working on a PHP project that uses a few functions
Here's the situation - I've got a shell that loads an external .swf. Now,
Situation: text: a string R: a regex that matches part of the string. This
I get a ISO-8859-1-encoded string from an exernal DLL, and I must use it
I have this situation - PhoneGap app running in Android. It uses external API
I have the following situation: I have a windows service that loads many external
I have a situation in Java where I have an external device that I
I have a situation where my main SWF file loads many external SWF files.
I have the following situation. Im getting data from an external system in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.