Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Misc > Re: freepascal ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 19 Topic 718 of 806
Post > Topic >>

Re: freepascal strings

by Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@[EMAIL PROTECTED] > Feb 18, 2007 at 02:01 PM

Richard Engebretson schrieb:
> Freepascal follows the turbo-pascal string type convention.

That depends on the mode and on the switch {$H+/-}.
Objpas and Delphi modes default to $H+, the other modes default to $H-.

In mode {$H-}, Strings are TP compatible. So I assume you are talking
about this mode.

> First, the string data type is created at compile time. Unlike C
> pointers created dynamically.
> 
> Second, a Pascal string is an indexed array. So a character can be
> addressed like S[3]. A length byte is at S[0].

Right.

> Third, string variables are passed to procedures as pointers.

That depends on how you declare the procedure!
a) procedure foo(s: String);
b) procedure foo(const s: String);
c) procedure foo(var s: String);

In b and c, a reference is used. In a, the string is copied to the stack.

> To create C strings (null terminated pointers to a sequence of
> characters) one might do the following;

You simply use StrPCopy.

> Turbo-Strings are different with some good reasons. Not necessarily a
> fault.

The main problem is that they have a maximum length of 255 characters.
That's one reason why I prefer AnsiString/{$H+}.

Some things that happen with AnsiStrings:
- s1:=s2 is just a pointer copy and reference counter change. The whole
data is copied only if you modify one of the strings.
- you can easily pass AnsiStrings to a procedure which expects a PChar:
simply use a cast: foo(PChar(str))
- s[0] is not the length (is is an error), get/set the length with
length() and setlength()

Wolf
 




 19 Posts in Topic:
freepascal strings
"Richard Engebretson  2007-02-17 19:16:39 
Re: freepascal strings
Wolf Behrenhoff <NoSpa  2007-02-18 14:01:05 
Re: freepascal strings
"Richard Engebretson  2007-02-19 03:13:17 
Re: freepascal strings
Wolf Behrenhoff <NoSpa  2007-02-19 15:22:41 
Re: freepascal strings
CBFalconer <cbfalconer  2007-02-19 19:04:06 
Re: freepascal strings
"Richard Engebretson  2007-02-19 09:09:46 
Re: freepascal strings
Marco van de Voort <ma  2007-02-19 20:41:13 
Re: freepascal strings
Wolf Behrenhoff <NoSpa  2007-02-19 22:09:24 
Re: freepascal strings
Marco van de Voort <ma  2007-02-20 08:38:07 
Re: freepascal strings
Wolf Behrenhoff <NoSpa  2007-02-20 13:58:34 
Re: freepascal strings
Jonas Maebe <Jonas.Mae  2007-02-20 14:58:14 
Re: freepascal strings
"Richard Engebretson  2007-02-19 09:37:20 
Re: freepascal strings
Wolf Behrenhoff <NoSpa  2007-02-19 21:19:34 
Re: freepascal strings
Marco van de Voort <ma  2007-02-19 20:43:07 
Re: freepascal strings
Wolf Behrenhoff <NoSpa  2007-02-19 21:56:35 
Re: freepascal strings
Marco van de Voort <ma  2007-02-19 21:19:37 
Re: freepascal strings
Marco van de Voort <ma  2007-02-19 21:27:00 
Re: freepascal strings
CBFalconer <cbfalconer  2007-02-19 19:07:59 
Re: freepascal strings
"Richard Engebretson  2007-02-19 13:15:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Jul 6 6:20:51 CDT 2008.