[fpc-pascal] Strings greater than 255 characters

Martin Frb lazarus at mfriebe.de
Tue Dec 19 14:35:41 CET 2023


On 19/12/2023 12:36, James Richters via fpc-pascal wrote:
>
> I did notice that I cannot have a file of Ansistrings…
>
> Myfile : File of Ansistring;
>
> Causes a compiler error:
>
> Error: Typed files cannot contain reference-counted types.
>
>

A "file of" must have a fixed size type.

"file of word", reads 2 byte (1 word) for each entry.

Shortstring always occupies 256 bytes
String[20] always 21 bytes
Even if such a string just contains "abc" it will have the full amount 
of bytes used in the file.

For ansistring that is not possible. It can have millions of chars, and 
you can't have each entry use 2^32 bytes.
If they don't have linebreaks, then you can just readln/writeln to/from 
a text file.

Mind: You can't replace just one string in the file by a different 
value, if the new string-value has a different length => then the entire 
rest of the file needs to be moved.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20231219/8f008a1b/attachment-0001.htm>


More information about the fpc-pascal mailing list