Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

i have a syntax problem creating records

1 view
Skip to first unread message

DB

unread,
Feb 1, 2005, 4:45:01 PM2/1/05
to
Can someone help me? This is driving me crazy.
I have simplified my unit down to this.
I need to create several units that have different types of data.
I want to create records of different kinds of data.
Each unit has its own type and structure of data records.
I want to preload each unit with some fixed records.

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 ==========

Bruce Roberts

unread,
Feb 1, 2005, 4:38:47 PM2/1/05
to

"DB" <danny....@sympatico.ca> wrote in message
news:rstvv05ao13sei8fc...@4ax.com...

> Can someone help me? This is driving me crazy.

> 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?)


Maarten Wiltink

unread,
Feb 1, 2005, 6:05:37 PM2/1/05
to
"DB" <danny....@sympatico.ca> wrote in message
news:rstvv05ao13sei8fc...@4ax.com...
[...]

> 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

It's "( FSName: '0123456789', FSLimit: 1.1 )".
Or perhaps a semicolon instead of the comma.

Groetjes,
Maarten Wiltink


Terry Russell

unread,
Feb 1, 2005, 8:40:57 PM2/1/05
to

"DB" <danny....@sympatico.ca> wrote in message
news:rstvv05ao13sei8fc...@4ax.com...
> Can someone help me? This is driving me crazy.
> I have simplified my unit down to this.
> I need to create several units that have different types of data.
> I want to create records of different kinds of data.
> Each unit has its own type and structure of data records.
> I want to preload each unit with some fixed records.
>
> 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) ) ;

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;

VBDis

unread,
Feb 3, 2005, 4:26:49 AM2/3/05
to
Im Artikel <rstvv05ao13sei8fc...@4ax.com>, DB
<danny....@sympatico.ca> schreibt:

>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

0 new messages