* * *

Author Topic: [Solved] Constant array of record  (Read 627 times)

jacmoe

  • Sr. Member
  • ****
  • Posts: 255
    • Jacmoe's Cyber SoapBox
[Solved] Constant array of record
« on: March 01, 2017, 01:37:58 pm »
I am still quite new/rusty in Pascal ( and this is Turbo Pascal ) ..

Trying to convert this C code:
Code: Pascal  [Select]
  1. typedef struct xy {
  2.         int x, y;
  3. };
  4.  
  5. struct xy increment[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
  6. struct xy left[4] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
  7. struct xy right[4] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
  8. struct xy pos = {1,3};
  9.  

So, this is the type:
Code: Pascal  [Select]
  1. type
  2.     xy = record
  3.         x : integer;
  4.         y : integer;
  5.     end;
  6.  

And the constants:
Code: Pascal  [Select]
  1. const
  2.     increment : array[0..4] of xy = (
  3.         ????
  4.     );
  5.  

Is there something better?

The constants / records are going to be used like this:
Code: Pascal  [Select]
  1.                 // Find current square of maze
  2.                 block.x = pos.x + dist * increment[direction].x;
  3.                 block.y = pos.y + dist * increment[direction].y;
  4.  
Translated into Pascal, of course.

I tried to write the array of records, like this:
Code: Pascal  [Select]
  1. ((x:1;y:1;), ...)
And Turbo Pascal yells at me: "invalid ordering of fields"
« Last Edit: March 01, 2017, 01:57:03 pm by jacmoe »
more signal - less noise

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5573
Re: Constant array of record
« Reply #1 on: March 01, 2017, 01:48:07 pm »
Probably the trailing ; before the )

But this is not a Turbo Pascal forum. Please test with FPC.

jacmoe

  • Sr. Member
  • ****
  • Posts: 255
    • Jacmoe's Cyber SoapBox
Re: Constant array of record
« Reply #2 on: March 01, 2017, 01:56:15 pm »
Probably the trailing ; before the )
Yes! It was that simple - thanks  :D

But this is not a Turbo Pascal forum. Please test with FPC.
Aye. I will paste it into FP before asking  ;D
more signal - less noise

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus