Frank Heckenbach wrote:
Russell Whitaker wrote:
This used to work:
... before GPC did range checking. ;-)
program fil; var i : integer; s : string( 500 ); begin for i := 1 to 500 do s[ i ] := ' '; writeln("ok"); end.
Now I get "Value out of range"
The length of the string is uninitalized (and probably happens to be 0), so accesss to characters > 0 (i.e., all ;-) is out-of range.
You could do `SetLength (s, 500)' before the loop, or `uses GPC; [...] s := StringOfChar (' ', 500);' instead of the loop.
This certainly sounds like a semantics problem to me. I would normally expect to see the string extended by the writing action, with the range error based on the capacity. I see no easy answer that will be both secure and expected. Obviously there is automatic string initialization going on, and it sounds as if it is the simplest, i.e. the capacity and length. Maybe the StringOfChar(' ', length) should be called as part of the default initialization.