[fpc-pascal] newbie questions
albertonarduzzi at yahoo.com
Tue Apr 20 00:04:39 CEST 2010
> Thank you.
> Does this mean that to be able to define a literal value like "byteset := [0, 3, 101]" for a set (and probably for an array) I must have defined a custom type for it; correct? (It's the only difference I see with my trials: numbers in my code is not of a custom type but simply a var of type "Set of Integer".)
> What I mean is, if the value is a literal, instead of only declaring the var then defining its value, one must first make a custom type for it? I don't understand the need & purpose of custom types except for records & enums; but this may be caused by the fact I come from dynamic languages.
IIRC, you need define a custom type (e.g. TByteSet = Set Of Byte) only
if you need to pass it to a function, that is, you cannot write:
Function CheckMySet(Var I:Set Of Byte):Integer;
Function CheckMySet(Var I:TByteSet):Integer;
Then, as you've been told, sets are represented as 0/1 bits in an array
of 32 bytes (32 x 8 = 256), hence in your set you can only have values
from 0 to 255 => no integers here...
For "sets" including bigger values, such as integers (or even reals) you
could use a TStringList and its IndexOf(); thou' it may not be
performant. Or use an array of sets...
Just my 2c.
More information about the fpc-pascal