[fpc-pascal] Having trouble defining an initialized constant correctly
Sven Barth
pascaldragon at googlemail.com
Sat Dec 18 12:02:51 CET 2010
On 17.12.2010 23:33, Cox, Stuart TRAN:EX wrote:
> Please excuse me if I’ve posted this request to the wrong list. I really
> did spend some time in trying to find a FPC list for simple coding
> questions. Sorry.
>
Yes, I'd say you've found the correct list ^^
> I have a set of record types defined and want to create an
> initializedconstant and anarrayconstant with values. OccasionallyI find
> thatI just cannot get the structure of the constantswritten properly and
> the compiler whines at me until I throw my hands in the air. I’d really
> appreciate it if someone could show me what I’m not able to see for myself.
>
To sum it up: you have to keep track to where you have to close your
parenthesis (see below).
[snip]
>
> {Then the hard part:}
>
> Const
>
> { one wee little one}
>
> LSegmentNull : TLSegment = (Srecord:(sSegLabID:(sLabel:'';
>
> segmentNo:maxlongint)
>
> );
>
> segment:((x:maxlongint;y:maxlongint),
>
> (x:maxlongint;y:maxlongint)));
>
> trueLP:(x:maxlongint;y:maxlongint));
You end the "Srecord" after the "segmentNo" with the ");", but "segment"
is also part of "Srecord". So put the ";" behind the closing parenthesis
of "sSegLabID" and remove the ");" before "segment".
It should look like this (formatted a bit differently to highlight the
end of a record a bit better):
LSegmentNull: TLSegment = (
Srecord: (
sSegLabID: (
sLabel:'';
segmentNo:maxlongint
);
segment: (
(x:maxlongint; y:maxlongint),
(x:maxlongint; y:maxlongint)
)
);
trueLP: (
x:maxlongint;
y:maxlongint
)
);
>
> { an array of five of the little blighters}
>
> CexistingLines : TexistingLines5= (
>
> (Srecord:(sSegLabID:(sLabel:’0’;segmentNo:0));segment:((x:0.5;y:0.5),(x:3.5;y:1.7));trueLP:(x:0.5;y:0.5)),
>
> (Srecord:(sSegLabID:(sLabel:’1’;segmentNo:1));segment:((x:1.0;y:4.0),(x:5.8;y:2.8));trueLP:(x:1.0;y:4.0)),
>
> (Srecord:(sSegLabID:(sLabel:’2’;segmentNo:2));segment:((x:1.5;y:3.0),(x:6.2;y:2.4));trueLP:(x:1.5;y:3.0)),
>
> (Srecord:(sSegLabID:(sLabel:’3’;segmentNo:3));segment:((x:2.3;y:4.3),(x:6.8;y:4.7));trueLP:(x:2.3;y:4.3)),
>
> (Srecord:(sSegLabID:(sLabel:’4’;segmentNo:4));segment:((x:2.5;y:0.3),(x:6.8;y:4.7));trueLP:(x:2.5;y:0.3))
>
> );
>
You have a similar problem here:
For one record ({!} marks the corrected points):
Srecord: (sSegLabID: (sLabel: '0';segmentNo:0); {!}
segment:((x:0.5;y:0.5),(x:3.5;y:1.7))); {!} trueLP: (x:0.5;y:0.5)
> Can anyone save me from my misery?
You should try to develop a formatting for such constant record
definitions that allows you to spot parenthesis errors quickly.
Regards,
Sven
More information about the fpc-pascal
mailing list