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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:52:46+00:00 2026-06-18T15:52:46+00:00

I understand that in Delphi, an empty string (AnsiString or WideString) can be represented

  • 0

I understand that in Delphi, an empty string (AnsiString or WideString) can be represented by a nil pointer, or by a pointer to an actual empty string.

By experiment I’ve shown that in Delphi XE2 (with particular compiler settings) PChar('') <> nil. But is this guaranteed, or might it change in a future version, or be dependent on some compiler setting?

I’m having a crisis of confidence. If anyone can give me a definitive answer I’d be grateful.

  • 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-06-18T15:52:48+00:00Added an answer on June 18, 2026 at 3:52 pm

    Yes. Type casts from string literals to PChar will never be null pointers. Type casts from strings of the same character type to PChar won’t be null, either. (String to PChar, AnsiString to PAnsiChar, etc.)

    Type casts of other things to PChar may be null, though. (Pointer to PChar, AnsiString to PWideChar, etc.)

    The documentation covers this in the Mixing Delphi Strings and Null-Terminated Strings section of the String Types topic:

    You can also cast a UnicodeString or AnsiString string as a
    null-terminated string. The following rules apply:

    • If S is a UnicodeString, PChar(S) casts S as a null-terminated string; it returns a pointer to the first character in S. Such casts
      are used for the Windows API. For example, if Str1 and Str2 are
      UnicodeString, you could call the Win32 API MessageBox function like
      this: MessageBox(0, PChar(Str1), PChar(Str2), MB_OK);. Use
      PAnsiChar(S) if S is an AnsiString.
    • You can also use Pointer(S) to cast a string to an untyped pointer. But if S is empty, the typecast returns nil.
    • PChar(S) always returns a pointer to a memory block; if S is empty, a pointer to #0 is returned.
    • When you cast a UnicodeString or AnsiString variable to a pointer, the pointer remains valid until the variable is assigned a new value
      or goes out of scope. If you cast any other string expression to a
      pointer, the pointer is valid only within the statement where the
      typecast is performed.
    • When you cast a UnicodeString or AnsiString expression to a pointer, the pointer should usually be considered read-only. You can
      safely use the pointer to modify the string only when all of the
      following conditions are satisfied:

      • The expression cast is a UnicodeString or AnsiString variable.
      • The string is not empty.
      • The string is unique – that is, has a reference count of one. To guarantee that the string is unique, call the SetLength, SetString, or
        UniqueString procedures.
      • The string has not been modified since the typecast was made.
      • The characters modified are all within the string. Be careful not to use an out-of-range index on the pointer.

    The same rules apply when mixing WideString values with PWideChar
    values.

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

Sidebar

Related Questions

I'm translating some C# code to Delphi, I understand that(msg = TMsg): (int)msg.LParam is
I understand that applications under the same domain name can talk to each other
I understand that we can set the various style attributes from code behind using
Are there any tools that can generate dependency diagrams for Delphi units taking into
I am looking for a software that can reverse engineering a delphi 2010 project
How can I slow down a Windows Process? I understand that I need to
I understand that: '\n' // literally the backslash character followed by the character for
I understand that JVM and CLR were designed as stack-based virtual machines. When JIT
I understand that the em measurement is a relative unit for font-size, relative to
I understand that this question may be subjective, this is why I need an

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.