Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-12

a problem about pascal programing

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

馮文杰

Hi,
I am beginner of pascal programing. I have a question about that I can't use a numeral as am element of enumerated data type such as"type items=(1,2,3,4)". You may refer to the attached file to get more information abou my problem. I am looking forward the help from you.Thanks.

Best regards

Wen-jei Fon 12/15 2001 Taiwan

Reply by email

Adam Naumowicz
to 馮文杰
[big5] ����N wrote
Hi, I am beginner of pascal programing. I have a question about that I can't use a numeral as am element of enumerated data type such as"type items=(1,2,3,4)". You may refer to the attached file to get more information abou my problem. I am looking forward the help from you.Thanks.

.....

type items=(1,2,3,4);

Only valid pascal identifiers can be used in enumerated type declaration. FPC supports also C-style enums (assigned enumerated types, see FPC's reference guide). But I suppose that in your case a subrange type like:

type items = 1..4;

can be used (altough I can't see no serious reason for so strict range checking at all in the program you attached).

Regards,
Adam Naumowicz

--------------------------------------
WWW: http://math.uwb.edu.pl/~adamn/
--------------------------------------

Reply by email

Gabor DEAK JAHN
to 馮文杰: I am beginner of pascal programing. I have a question about that I can't use a numeral as…

At 12/15/2001 10:55 PM, you wrote:

Wen-jei,

I am beginner of pascal programing. I have a question about that I can't

use

a numeral as am element of enumerated data type such as "type items=(1,2,3,4)". You may refer to the attached file to get more

information

You're mixing two different concepts. Enumeration is a series of constants, practically a simpler way to specify a series of constants. This means that the elements of the list have to be identifiers, not numbers like in your "type items = (1,2,3,4)" line.

What you are looking for is a subrange type, an integer whose range of possible values is reduced. You can declare it with the syntax "type items = 1..4".

It depends on your actual requirements whether you need this or not. In your program, you don't. If you step a variable from 4 to 1 with the compiler, you can be sure the value will iterate from 4 to 1 all right, there is no need for additional checking. But even if you need some range checking in other places, you probably don't want to have a hostile runtime error, so using a simple IF and showing your own error message (or correcting the error yourself is it is feasible in the actual situation) could be a much better alternative.

Bye,
Gábor

------------------------------------------------------------------- Gabor DEAK JAHN -- Budapest, Hungary.
E-mail:

Reply by email