Solved

Empty and null string

Posted on 2001-06-30
5
341 Views
Last Modified: 2010-04-06
Hi
I'm a bit confused when the Win32 sdk talks about that a string should be empty or null.
Could somebody clear things up.

if a pchar is assigned to nil then it is a null string ?
if it's an empty string then ..
0
Comment
Question by:bnz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 14

Accepted Solution

by:
AvonWyss earned 50 total points
ID: 6240488
Windows uses Zero-Terminated (also called C-Style) strings. They are terminated with a #0 char. So, if you have a PChar pointing to a #0, it points to an empty string. If you have a PChar pointing to nil, it's NULL...
0
 
LVL 2

Expert Comment

by:bugroger
ID: 6240497
Hi,

var
 ts : pchar;

begin
 //before ts set to '' ts is nil = NULL string
 ts := '';
 //after ts set to '' ts is an empty string
 //-> "pointing to a #0"
0
 

Author Comment

by:bnz
ID: 6240507
is '' equal #0 ?
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6240534
bnz, Zero-Terminated strings are terminated by #0. So if you have an empty string, the PChar will therefore point to a #0 (that is, there are no other chars between the beginning of the string and the #0 terminating the string). Because of this, Delphi will substitute '' to a pointer pointing to a #0.
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6240535
(but be aware that '' on other string types than Zero-Terinated will NOT point to a #0; for instance, the Delphi ANSI strings will be set to nil if '' is assigned!)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question