Are you blogging on PH? Get your free blog.

View \HINTS.TXT

Using Null Terminated String Handling

Submitted By: Unknown
Rating: (Not rated) (Rate It)


Using Null Terminated Strings in Turbo Pascal 6
===============================================


     Unlike Turbo Pascal for Windows the Turbo Pascal 6.0
compiler does not have support for null terminated strings.
Therefore there are some things which have to be stated
differently. It must be said, though, that once you have made the
described alterations the a program will still compile
successfully under Turbo Pascal for Windows.


     Included with the unit is a file called 'STRINGTE.PAS'. This
demonstrates the use of the strings unit. This program can also
be used along with the Turbo Pascal IDE Debugger to see that the
strings unit is working correctly.

Syntax
======

Constant Null terminated strings.
--------------------------------

These are defined by

const
 foostring : array [0..foolen] of char = 'FooText etc'#0;

They are referred to when passing then to functions by:

 @foostring[0]

This literally passes the address of the first character in the
string to the function.


Var type Null terminated strings.
---------------------------------

These are defined by

var
 foovar : array [0..foolen] of char;

To blank one of these strings you could use:
  foovar[0]:=#0;

or alternatively
  Fillchar(foovar,Sizeof(foovar),#0);

Dynamic type Null terminated Strings.
====================================

These are defined by
     var
      foodynamic : pChar;


They are allocated on the heap using StrNew and Released by using
StrDispose. You must use StrDispose to release memory allocated
with StrNew. Since StrNew also keeps a check on the length of
string allocated so always the correct amount is released even if
a null is introduced into the middle of the string.

To refer to a specific character in a null terminated string you
must use:

ptChar(foodynamic)^[foocharno]

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.