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

  • SEARCH
  • Home
  • 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 7640863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:46:42+00:00 2026-05-31T08:46:42+00:00

I am trying to convert some old Delphi 7 code to Delphi 2010 function

  • 0

I am trying to convert some old Delphi 7 code to Delphi 2010

function AnsiToDOS(S: String): String;
begin
  SetLength(Result, Length(S));
  if S <> '' then begin
     CharToOEM(PChar(S), PChar(Result));
  end;
end;

I get the “Incompatible types: ‘Char’ and ‘AnsiChar’ ” error at the line:

CharToOEM (external User32 function) found in

Windows.pas unit

Can I rewrite this AnsiToDos function somehow, or do I need to write my own CharToOEM routine?

  • 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-31T08:46:43+00:00Added an answer on May 31, 2026 at 8:46 am

    In Unicode Delphi, CharToOem maps to the Unicode version CharToOemW which has the following signature:

    function CharToOem(Source: PWideChar; Dest: PAnsiChar): BOOL; stdcall;
    

    So you need to supply an ANSI output buffer but your code provides a Unicode output buffer.

    The natural conversion is to switch to an AnsiString return value. At the same time renamed the function as StringToOem to better reflect what it does.

    function StringToOem(const S: String): AnsiString;
    begin
      SetLength(Result, Length(S));
      if S <> '' then begin
        CharToOem(PChar(S), PAnsiChar(Result));
      end;
    end;
    

    An alternative would be to convert to OEM in place, but for this you need to pass in an ANSI string and call the ANSI version of the API call explicitly.

    function AnsiStringToOem(const S: AnsiString): AnsiString;
    begin
      Result := S;
      UniqueString(Result);
      if S <> '' then begin
        CharToOemA(PAnsiChar(Result), PAnsiChar(Result));
      end;
    end;
    

    I do have to comment that I am surprised to see the OEM character set still being actively used in the modern day. I thought it had gone the way of the dinosaurs!

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

Sidebar

Related Questions

Im trying to convert some Delphi code to c# and I've come across a
I'm trying to convert some old 32 bit code to 64 bit. One of
I am trying to convert some old VB6 code to VB.NET. The VB6 uses
I'm trying to convert some code that worked great in VB, but I can't
I'm trying to convert some code from C# to C so that it can
I am having some issues trying to convert a double to C++ string. Here
There is some code that I'm trying to convert from IList to IEnumerable :
I am trying to convert some Cocos2d-iphone code to Cocos2d-x code and could use
I'm trying to convert some Haskell code to F# but I'm having some trouble
I'm trying to convert some c code to assmebly, and I need some help.

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.