J. David Bryan wrote:
On 11 Oct 2001, at 16:40, Theo Carr-Brion wrote:
I am using gpc 20010924 with gcc 2.95.3 on UnixWare 7.1 and the following code does not work.
It fails on gpc 20010604 as well.
The following modification to your program illustrates the source of the error:
Program Test2(Output);
Type Str10 = String(10); LetterType = (AA, BB, CC, DD); MyRec = record LetterName: Array[LetterType] of Str10; end;
var ThisLetter: LetterType; ThisRec: MyRec;
begin for ThisLetter:=AA to DD do writeln (ThisRec.LetterName[ThisLetter].Capacity); end.
The problem is that "Capacity" is not being set for all four strings during program initialization (the type "String" is a schema consisting of "Capacity" -- the maximum length of the string, "Length" -- the current length of the string, and the actual characters themselves). To avoid overrunning the target string, the string assignment in the "SetIt" procedure assigns the shorter of the source string length and the target string capacity. As the target string capacity is not being set for the third and fourth strings in the array, their capacities are defaulting to zero. Therefore, the third and fourth string assignments are failing.
Theo Carr-Brion wrote:
The problem seems to be a general one with variables of Array[AType] of String(Capacity) which we use quite a lot. The capacity of the string if not always set. Sometimes it works and sometimes it does not and I can't find the pattern. Setting the capacity of each string in the program gets round the problem.
I think I found and fixed the problem (will be uploaded soon). It was a blatant type error inside GPC, so it's no wonder that it seemed to occur quite irregular. (theo1[ab].pas)
Frank