Solved

Empty and null string

Posted on 2001-06-30
5
339 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi inherited method 6 78
DBCtrlGrid, Delphi, Scroll 8 55
FMX TEdit KeyUp handler detecting  "enter" key 4 36
Can Live bindings change TGrid Cell Colour ? 1 29
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 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