Constant with complex type

General discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
trengtor
Posts: 94
Joined: 06 May 2014 16:33

Constant with complex type

#1 Post by trengtor » 10 May 2014 06:10

Hi All! I need you help! I tried to use such construction:

Code: Select all

const cNumOfPoint : byte = 4;
      cNumOfChannels : byte = 3;

type tControlPoint = record 
       PointTgrad : integer;
       PointPWM : word;
     end;
     tControlCurve = array [1..cNumOfPoint] of tControlPoint; 
     tChannelsControl = array [1..cNumOfChannels] of tControlCurve; 

type tCurrentTgrad = array [1..cNumOfChannels] of integer; 
     tCurrentPWM = array [1..cNumOfChannels] of word; 

const defChannelsPWM : tChannelsControl = (((PointTgrad:20;PointPWM:020), (PointTgrad:30;PointPWM:030), (PointTgrad:40;PointPWM:040), (PointTgrad:50;PointPWM:100)),
                                           ((PointTgrad:20;PointPWM:020), (PointTgrad:30;PointPWM:030), (PointTgrad:40;PointPWM:040), (PointTgrad:50;PointPWM:100)),
                                           ((PointTgrad:20;PointPWM:020), (PointTgrad:30;PointPWM:030), (PointTgrad:40;PointPWM:040), (PointTgrad:50;PointPWM:100))); 
Compiler returns me '303 Identifier "PointTgrad" was not declared 111.mpas' for 'const defChannelsPWM : tChannelsControl = (((PointTgrad:20;PointPWM:020), ...'

Can I use such constants or MP has syntax restrictions?

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Constant with complex type

#2 Post by Dany » 10 May 2014 11:14

Hi, in mP you should not repeat the member names of a record (as you should in Delphi),
so your definition should look like this:

Code: Select all

const defChannelsPWM : tChannelsControl = (
                                           (
                                           (20,020),
                                           (30,030),
                                           (40,040),
                                           (50,100)
                                           ),
                                           (
                                           (20,020), 
                                           (30,030), 
                                           (40,040), 
                                           (50,100)
                                           ),
                                           (
                                           (20,020), 
                                           (30,030), 
                                           (40,040), 
                                           (50,100)
                                           )
                                          );
To test use:

Code: Select all

var Ptr:^const byte;

begin
  Ptr := @DefChannelsPWM;
end.
In the list file you can find then the constant that was generated:

Code: Select all

;Textx.mpas,18 :: _defChannelsPWM
0x002A        0x0014 ;_defChannelsPWM+0
0x002C        0x0014 ;_defChannelsPWM+2
0x002E        0x001E ;_defChannelsPWM+4
0x0030        0x001E ;_defChannelsPWM+6
0x0032        0x0028 ;_defChannelsPWM+8
0x0034        0x0028 ;_defChannelsPWM+10
0x0036        0x0032 ;_defChannelsPWM+12
0x0038        0x0064 ;_defChannelsPWM+14
0x003A        0x0014 ;_defChannelsPWM+16
0x003C        0x0014 ;_defChannelsPWM+18
0x003E        0x001E ;_defChannelsPWM+20
0x0040        0x001E ;_defChannelsPWM+22
0x0042        0x0028 ;_defChannelsPWM+24
0x0044        0x0028 ;_defChannelsPWM+26
0x0046        0x0032 ;_defChannelsPWM+28
0x0048        0x0064 ;_defChannelsPWM+30
0x004A        0x0014 ;_defChannelsPWM+32
0x004C        0x0014 ;_defChannelsPWM+34
0x004E        0x001E ;_defChannelsPWM+36
0x0050        0x001E ;_defChannelsPWM+38
0x0052        0x0028 ;_defChannelsPWM+40
0x0054        0x0028 ;_defChannelsPWM+42
0x0056        0x0032 ;_defChannelsPWM+44
0x0058        0x0064 ;_defChannelsPWM+46
; end of _defChannelsPWM
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

trengtor
Posts: 94
Joined: 06 May 2014 16:33

Re: Constant with complex type

#3 Post by trengtor » 10 May 2014 19:47

Dany, many thanks!

Post Reply

Return to “mikroPascal PRO for AVR General”