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.
Program Test(Input, Output);
Type Str10 = String(10); LetterType = (AA, BB, CC, DD); MyRec = record LetterName: Array[LetterType] of Str10; end; procedure SetIt(var aStr1: String; const aStr2: String); begin aStr1:=aStr2; end;
var ThisLetter: LetterType; ThisRec: MyRec;
begin for ThisLetter:=AA to DD do SetIt(ThisRec.LetterName[ThisLetter], Chr(Ord(ThisLetter)+Ord('A')));
^^^ I don't know just what a str10 or a string is (apart from an extension), but this is not one, this is a character. The question is why didn't the compiler refuse this faulty procedure call?
for ThisLetter:=AA to DD do WriteLn(ThisRec.letterName[ThisLetter]); for ThisLetter:=AA to DD do ThisRec.LetterName[ThisLetter]:=Chr(Ord(ThisLetter)+Ord('A'));
^^^ Same thing here.
for ThisLetter:=AA to DD do WriteLn(ThisRec.LetterName[ThisLetter]); end.
The first set of WriteLn commands prints out A and B and then spaces. The second set prints out A to D as expected.