[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 6.2.1 String type

GPC's internal string format (Extended Pascal string schema) is different from BP's. BP compatible short strings will be implemented in GPC soon, but in the meantime, you'll have to live with the difference. In general, GPC's format has many advantages (no length limit of 255 characters, constant and reference parameters always know about their capacity, etc.), but you will see differences if you:

- declare a variable as ``String'` without a capacity. However, GPC will assume 255 then (like BP) and only warn about it (and not even this when using ``--borland-pascal'`, see below), so that's not a real problem. The "clean" way, however, is to declare ``String [255]'` when you mean so (but perhaps you'll prefer ``String (2000)'`? :-).

- access "character 0" which happens to hold the length in BP. This does not work with string schemata. Use ``Length'` to get the length, and ``SetLength'` to modify it.

- try to ``FillChar'` a string, e.g. ``FillChar (StringVar, 256, 0);'`, which would overwrite the ``Capacity'` field. Using ``FillChar (StringVar[1], ...);'` is alright since it accesses the characters of the string, not the ``Capacity'` and ``Length'` fields. If you want to set the length to zero, use ``SetLength'` (see above) or simply assign an empty string (``StringVar := "'`). This is more efficient than clearing all the characters, anyway, and has the same effect for all normal purposes.

- try to read or write strings from/to binary files (``Text'` files are no problem). You will have to rewrite the code. If you also want to get rid of the 255 character limit and handle endianness issues (see below) in one go, you can use the ``ReadStringLittleEndian'` etc. routines (see section 8.13 Pascal declarations for GPC's Run Time System), but if you need BP compatible strings (i.e., with a one-byte length field) in data files, you cannot use them (but you can easily modify them for this purpose).

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by Frank Heckenbach on May, 10 2002 using texi2html