When i try to compile this I get the error show below.
====== my simplified code ==========
unit ENG99 ;
interface
Const
RecCount: integer = 3 ;
type
TFsItem = record
FSName: string[10] ;
FSLimit: single ;
end ;
const
UFS: array[0..RecCount] of TFsItem =
( ('0123456789', 1.1), //Problem Here
//')' expected but string constant found
('bbbbbbbbbb', 2.2),
('cbbbbbbbbb', 3.3),
('dddddddddd', 4.4) ) ;
var
i1: integer ;
function Getname(i1): string ;
implementation
function Getname(i1): string ;
begin
Getname := UFS[i1].Name ;
end ;
end .
====== end of code ==========
> Const
> RecCount: integer = 3 ;
This is a 'Typed Constant' which is different from a Pascal (literal)
constant.
> const
> UFS: array[0..RecCount] of TFsItem =
Since historically, at least, Typed Constants could be changed they are not
permitted as array bounds in Const declarations. Try
Const RecCount = 3;
. . .
Const UFS : array [0 .. RecCount] of tFsItem = . . .
(BTW you realize that this will create a 4 record array, not one of 3
(RecCount) records?)
It's "( FSName: '0123456789', FSLimit: 1.1 )".
Or perhaps a semicolon instead of the comma.
Groetjes,
Maarten Wiltink
see help 'record constants'
Const RecCount = 3 ;
type
TFsItem = record
FSName: string[10] ;
FSLimit: single ;
end ;
const
UFS: array[0..RecCount] of TFsItem =
( (fsname:'0123456789' ; fslimit:1.1),
( order is important, so why demand name?
maybe to discourage this form ? :-)
with cutnpaste it isn't much of a problem unless redesigning
)
for larger record arrays helper functions are useful
just a pain for small arrays
but then ..if it becomes a pain to write it the first time
you probably will be thankful later if you
wrap all the init/get/set helpers into a class anyway :-)
var
vUFS: array[0..RecCount] of TFsItem;
procedure initvUFS;
procedure setrec(i:integer;s:string;r:single);
begin
vufs[i].fsname:=s;
vufs[i].fslimit:=r;
end;
begin
setrec(0,'0123456789',1.1);
setrec(1,'1123456789',2.2);
setrec(2,'2123456789',3.1);
setrec(3,'3123456789',4.1);
end;
>Const
> RecCount: integer = 3 ;
Should be changed to either:
const RecCount = 3;
or
type TRecCount = 0..3; //better Pascal ;-)
>type
> TFsItem = record
> FSName: string[10] ;
> FSLimit: single ;
> end ;
>const
> UFS: array[0..RecCount] of TFsItem =
> ( ('0123456789', 1.1), //Problem Here
> //')' expected but string constant found
convert all initializers into:
( (FSName='0123456789'; FSLimit=1.1), ...
DoDi