Hi Thanks for the prompt and detailed reply.
Below is a copy of program with errors removed.
Noteable: 1. a var declaration is required before a type declaration. 2. later on, the varible just declared really isn't needed. in this case a "new(ptrline, length( Aline ))" works just as well.
There may be several ways you could redesign gpc to remove the var requirement. One way would be to allow a dummy varible in a type declaration so new() would know there is more than one item.
Russ
unit Buff; interface
const MAXLINES = 20000;
type lline = string ( 4000 );
procedure BB_AddLine( Aline: lline ); {adds to end}
implementation var cap : integer;
type ptrline = ^Line; Line = string ( cap );
TbbArray = array[1..MAXLINES] of ptrline;
var BigBuffer : Tbbarray; {array of pointers to data} LineCount : integer = 0;
procedure BB_AddLine( Aline: lline ); begin inc( LineCount ); cap := length( Aline ); BigBuffer[ LineCount ] := new( ptrline, cap ); BigBuffer[ LineCount ]^ := Aline; end; end.
Russell Whitaker wrote:
Hi Thanks for the prompt and detailed reply.
Below is a copy of program with errors removed.
Noteable:
- a var declaration is required before a type declaration.
- later on, the varible just declared really isn't needed. in this case a "new(ptrline, length( Aline ))" works just as well.
There may be several ways you could redesign gpc to remove the var requirement. One way would be to allow a dummy varible in a type declaration so new() would know there is more than one item.
I don't quite understand what you mean. This program declares Line as string of capacity cap which is uninitialized. If GPC accepts this, that may be considered a bug (but GPC doesn't yet check for uninitialized values in all situations, anyway).
If what you mean is to declare ptrline a pointer to a string of arbitrary capacity (and it seems like you do), just declare it as `^String'. (You can't declare a variable of type `String' (at least not without warning) because the capacity is missing, but you can declare a pointer as `^String', so perhaps you got that wrong.)
`New' knows that the capacity is required from the (implicit) declaration of `String' as `record (Capacity: Cardinal) ...' -- not `String (cap)' type required (or, strictly, even allowed, if you want to specify a capacity with `New').
The variable `cap' is not required in your code (only locally in the procedure, though could also move `Length (ALine)' into the `New' parameters).
unit Buff; interface
const MAXLINES = 20000;
type lline = string ( 4000 );
procedure BB_AddLine( Aline: lline ); {adds to end}
implementation var cap : integer;
type ptrline = ^Line; Line = string ( cap );
TbbArray = array[1..MAXLINES] of ptrline;
var BigBuffer : Tbbarray; {array of pointers to data} LineCount : integer = 0;
procedure BB_AddLine( Aline: lline ); begin inc( LineCount ); cap := length( Aline ); BigBuffer[ LineCount ] := new( ptrline, cap ); BigBuffer[ LineCount ]^ := Aline; end; end.
Frank