[fpc-pascal] Unicodestrings and Assign(File)

J├╝rgen Hestermann juergen.hestermann at gmx.de
Tue May 22 18:29:22 CEST 2012

Jonas Maebe schrieb:
 > That's a non sequitur:
 > a) even though the original code was written a long time ago, it has 
been changed many times since then
 > b) if it isn't broken, don't fix it. Example: changing all 
occurrences of "string" into "shortstring" will break the system unit.
 > The reason is that a "var a: string" is an "openstring" parameter 
(with a hidden "high" parameter that tells you the size of
 > the variable that was passed in), while "var a: shortstring" is not. 
So at the very least, you'd have to change var/out
 > parameters into openstring rather than into shortstring.

As far as I know you can pass ShortString of any size to a ShortString 
of maximum length (255). So I don't see how "var a : ShortString" would 
lead to errors. But of course, you need to be careful.

Nevertheless, I would rewrite such code. Even at the danger of breaking 
something else (which would hopefully appear directly) I would consider 
clear code so important that I would not rely on some compiler switch 
(that may change some day) to make it run. Especially because *if* the 
compiler switch is changed it would not strike you immediately. It would 
run a long time until someone (by accident) has a path longer than 255 
characters. And then it would not raise an exception (which would point 
you to the cause) but it would overwrite other data and then crash at a 
completely unrelated instruction (or just lead to wrong results).

More information about the fpc-pascal mailing list