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 6696887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:23:40+00:00 2026-05-26T06:23:40+00:00

For my purposes, I’m actually truly using ASCII character data (for submitting ASCII text

  • 0

For my purposes, I’m actually truly using ASCII character data (for submitting ASCII text files to the state), so just using unicodestring won’t help the end result (I’d still have to convert something).

I’ve got the option to convert a StrComp function in Delphi 2009 that went from comparing a AnsiString and an PAnsiChar to a UnicodeString and an PAnsiChar.

Val : PAnsiChar
Mask : TEditMask;

….

this is my original code, it’s not good

StrComp(PAnsiChar(Mask.EditText), Val);

….

so, I can change it to this:

StrComp(PAnsiChar(AnsiString(MAskEdit.EditText), Val);

or, I can change it to this (extra conversions for ‘clarity’):

StrComp(PChar(MAskEdit.EditText), PChar(String(AnsiString(Val))));

I remember Marco Cantu saying, don’t do one of these in a loop, I just don’t remember which one or why.

  • 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-26T06:23:40+00:00Added an answer on May 26, 2026 at 6:23 am

    If you compile this:

    StrComp(PAnsiChar(Mask.EditText), Val);
    

    There is an implicit conversion from the Mask.EditText as UnicodeString into a temporary AnsiString in order to allow the type cast to PAnsiChar. That is your 2nd line:

    StrComp(PAnsiChar(AnsiString(MAskEdit.EditText), Val);
    

    But writing

    StrComp(PChar(MAskEdit.EditText), PChar(String(AnsiString(Val))));
    

    will let PChar(MAskEdit.EditText) return a PChar, that is a PWideChar, so it will use the other overloaded StrComp function.

    In fact, there are two overloaded functions defined since Delphi 2009 in SysUtils.pas:

    function StrComp(const Str1, Str2: PAnsiChar): Integer; overload;
    function StrComp(const Str1, Str2: PWideChar): Integer; overload;
    

    Both functions won’t call the windows API, but will compare the characters one by one, with case sensitivity.

    So my advice is that you simply do not use any pointer in your code, but rely on plain string = UnicodeString variables everywhere in your code, and use this function instead:

    function CompareStr(const S1, S2: string): Integer;
    

    The comparison will be the same, and there will be no hidden conversion. The issue with having WideChar instead of AnsiChar (i.e. having two times more memory) is nothing compared with the conversion (two WinAPI calls) between unicode and current ansi page. To quote your title, conversion direction does not matter: it is always much slower than no conversion.

    If you search about speed, I suspect that Mask.EditText is definitively the bottleneck in your code. This method will send a GDI message, wait for the response of the component, then affect a string with the text. You should better use a temporary variable on stack, if, as I suspect, you are using this Mask.EditText expression in a loop.

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

Sidebar

Related Questions

For testing purposes I need to create sets of text files that have similar
For the purposes of handling very large collections (and by very large I just
For debugging purposes, I need to recursively search a directory for all files which
For learning purposes, I'm trying to make a function using Python that takes in
For learning purposes I created a toy project using grails. In this project I
For purposes of testing compression, I need to be able to create large files,
for testing purposes i need an recursive directory with some files, that comes to
For debugging purposes in a somewhat closed system, I have to output text to
Just for my own purposes, I'm trying to build a tokenizer in Java where
For the purposes of this example, suppose there exist 2 binary files A and

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.