3.2.3 Short strings

A string declaration declares a short string in the following cases:

  1. If the switch is o: f$H-g, the string declaration will always be a short string declaration.
  2. If the switch is on f$H+g, and there is a length specier, the declaration is a short string declaration.

The predened type ShortString is dened as a string of length 255:

 ShortString = String[255];

If the size of the string is not specied, 255 is taken as a default. The length of the string can be obtained with the Length standard runtime routine. For example in

{$H-}  
 
Type  
  NameString = String[10];  
  StreetString = String;

NameString can contain a maximum of 10 characters. While StreetString can contain up to 255 characters.

Clarifications?

I think this documentation needs some clarification about size (maximum length) and (current) length.

At first about the maximum possible size of a string, I guess it's 255.
Although I haven't tried to write:
var s: string[1000];

On the other hand:
ShortString = String[255];
has a _maximum_ length of 255, you can of course assign shorter value to a variable of this type. The current length of its value can be obtained with the Length() function. To get its size - its maximum length - (SizeOf(s) - 1) can probably be used.

-- Unregistered Visitor on April 22, 2007 06:18 PM (view details)