John L. Ries wrote:
Correction: Makes no difference if I compile the types inside a program (or a module), rather than a unit, but if I change the definition of CandName to use a constant length, rather than a schema, the crash goes away.
Example:
const MaxCandName = 30;
type CandName = string(MaxCandName);
Eliminates the crash. Obviously, I'd rather use the schema.
Of course, the compiler should not crash, but the code is incorrect, since the discriminant for the "Name" record field is missing. The following modification compiles (with my GPC version), though I didn't write a test program to see if it works correctly.
The point is, you need to specify the value at some place. Here I only shift this place outwards, to the record and then the array type. If you want it to be dynamic at runtime, you need a pointer ("^CandName") which you can allocate with "New (Name, Value)" (and later "Dispose", usually).
unit example; interface
type CandName(MaxCandName:integer) = string(MaxCandName); CandStatus = (Elected, Eliminated, Neither); CandRecord(MaxCandName:integer) = record Name : CandName(MaxCandName); RawVote : integer; Allocation : integer; Status : CandStatus; end; CandArray(N,MaxCandName:integer) = array[1..N] of CandRecord(MaxCandName); end.
Frank