[fpc-pascal] Writeable typed constants - what's the point?

Paul Nicholls paulfnicholls at gmail.com
Fri Jun 19 02:47:15 CEST 2009


2009/6/18 Graeme Geldenhuys <graemeg at opensoft.homeip.net>

> Vincent Snijders wrote:
> >
> > Backwards compatibility with turbo pascal, which lacked initialized
> > variables and writable constants were the alternative.
>
> Thanks Vincent. The Kylix 3 help mentioned early versions of Delphi and
> Borland Pascal, which made me think that it must have been some
> limitation in the older compilers. Thanks for confirming this.
>
>
> Regards,
>  - Graeme -
>

I also find writable constants hand for things like this where I can define
the 'variable' + values too so I don't have to set the values at run time:

Const
{..............................................................................}
    cNote_Unknown = -1;
    cNote_C       = 0;
    cNote_Cs      = 1;  cNote_Db = 1;
    cNote_D       = 2;
    cNote_Ds      = 3;  cNote_Eb = 3;
    cNote_E       = 4;
    cNote_F       = 5;
    cNote_Fs      = 6;  cNote_Gb = 6;
    cNote_G       = 7;
    cNote_Gs      = 8;  cNote_Ab = 8;
    cNote_A       = 9;
    cNote_As      = 10; cNote_Bb = 10;
    cNote_B       = 11;
    cNotes : Array[0..11,0..8] Of Single =
    (
        //Octave
//Note    0                 1                 2
3                 4                 5                 6
7                 8
{C}      (16.3515978312874, 32.7031956625748, 65.4063913251497,
130.812782650299, 261.625565300599, 523.251130601197, 1046.50226120239,
2093.00452240479, 4186.00904480958),
{C#/Db}  (17.3239144360545, 34.647828872109 , 69.295657744218 ,
138.591315488436, 277.182630976872, 554.365261953744, 1108.73052390749,
2217.46104781498, 4434.92209562995),
{D}      (18.354047994838 , 36.7080959896759, 73.4161919793519,
146.832383958704, 293.664767917408, 587.329535834815, 1174.65907166963,
2349.31814333926, 4698.63628667852),
{D#/Eb}  (19.4454364826301, 38.8908729652601, 77.7817459305202,
155.56349186104 , 311.126983722081, 622.253967444162, 1244.50793488832,
2489.01586977665, 4978.03173955329),
{E}      (20.6017223070544, 41.2034446141088, 82.4068892282175,
164.813778456435, 329.62755691287 , 659.25511382574 , 1318.51022765148,
2637.02045530296, 5274.04091060592),
{F}      (21.8267644645628, 43.6535289291255, 87.307057858251 ,
174.614115716502, 349.228231433004, 698.456462866008, 1396.91292573202,
2793.82585146403, 5587.65170292806),
{F#/Gb}  (23.1246514194772, 46.2493028389543, 92.4986056779086,
184.997211355817, 369.994422711634, 739.988845423269, 1479.97769084654,
2959.95538169308, 5919.91076338615),
{G}      (24.4997147488593, 48.9994294977187, 97.9988589954373,
195.997717990875, 391.995435981749, 783.990871963499, 1567.981743927  ,
3135.96348785399, 6271.92697570799),
{G#/Ab}  (25.9565435987466, 51.9130871974931, 103.826174394986,
207.652348789973, 415.304697579945, 830.60939515989 , 1661.21879031978,
3322.43758063956, 6644.87516127912),
{A}      (27.5            , 55              , 110             ,
220             , 440             , 880             , 1760            ,
3520            , 7040            ),
{A#/Bb}  (29.1352350948806, 58.2704701897613, 116.540940379522,
233.081880759045, 466.16376151809 , 932.32752303618 , 1864.65504607236,
3729.31009214472, 7458.62018428944),
{B}      (30.8677063285078, 61.7354126570155, 123.470825314031,
246.941650628062, 493.883301256124, 987.766602512248, 1975.5332050245 ,
3951.06641004899, 7902.13282009799)
    );
{..............................................................................}


Notice the cNotes array - it is already filled with values for me to use at
runtime :)

cheers,
Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20090619/c74f5e9d/attachment.html>


More information about the fpc-pascal mailing list