Board index » delphi » Null Terminating Strings

Null Terminating Strings

Hi everybody it's me the dude that does not know anything.
Well today I was wondering about null terminating strings.  First since Pascal
does not support null terminating strings natively.  We have to use the strings
unit in pascal 7.  Now since it is a pointer (pchar) do we have to reserve spac
e on the heap for this variable?  Like when I declare something like this v :
^byte; I'll have to use new(v).  Do I have to use the same thing on pchar?
Also does the string terminate on chr(0) or #0?  thanks in advance.
 

Re:Null Terminating Strings


In article <95343.235609Y9...@CUNYVM.CUNY.EDU>, Deric <Y9...@CUNYVM.CUNY.EDU> says:

Quote

>Hi everybody it's me the dude that does not know anything.
>Well today I was wondering about null terminating strings.  First since Pascal
>does not support null terminating strings natively.  We have to use the strings
>unit in pascal 7.  Now since it is a pointer (pchar) do we have to reserve spac
>e on the heap for this variable?  Like when I declare something like this v :
>^byte; I'll have to use new(v).   Do I have to use the same thing on pchar?

Pretty much.  You can't really use new, as that will only allocate 1 character,
you should you GetMem or StrNew.  You also have to keep track of how much you
allocated so that you can free the same amount at the end.

Quote
>Also does the string terminate on chr(0) or #0?  thanks in advance.

chr(0)=char(0)=#0
Also remember that they alway start at index 0.
All in all they are a pain but have the advantage of not being limited
to 255 chars.  I'm looking forward to 32 bit Delphi where Pascal strings
can but MUCH longer.

Does this help?
Jochen

________________________________________________________________________
joch...@berlin.snafu.de                        71270.3...@compuserve.com
I post, therefore I am.

Re:Null Terminating Strings


Quote
In article <95343.235609Y9...@CUNYVM.CUNY.EDU> Deric <Y9...@CUNYVM.CUNY.EDU> writes:
>From: Deric <Y9...@CUNYVM.CUNY.EDU>
>Subject: Null Terminating Strings
>Date: Sat, 9 Dec 1995 23:56:09 EST
>Hi everybody it's me the dude that does not know anything.
>Well today I was wondering about null terminating strings.  First since Pascal
>does not support null terminating strings natively.  We have to use the strings
>unit in pascal 7.  Now since it is a pointer (pchar) do we have to reserve spac
>e on the heap for this variable?  Like when I declare something like this v :
>^byte; I'll have to use new(v).  Do I have to use the same thing on pchar?
>Also does the string terminate on chr(0) or #0?  thanks in advance.

chr(0) and #0 are the same thing.

Other Threads