Recent

Author Topic: cascaded record constants  (Read 3794 times)

lt.col.blair

  • New Member
  • *
  • Posts: 15
cascaded record constants
« on: October 24, 2014, 07:33:22 pm »
Hi,

Is it possible to define constants that are made up of records which again contain records?

My structures are like this:
Code: [Select]
RDartPolar = record
  Radius: NRadius;
  Field: NField;
end;

RBoardPosition = record
  BoardPos: RPolar;
  RectPos: TPoint;
end;

const
  PolarNULL: RDartPolar=(Radius: radMissed; Field: fld20);
  PointNULL: TPoint = (X: -1000; Y: -1000);
  DartNULL: RBoardPosition=(BoardPos: PolarNULL; RectPos: PointNULL); //raises compiler error '"(" expected but identifier PolarNULL found.'

Is this an illegal construction or do I have some other error in my code?

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: cascaded record constants
« Reply #1 on: October 24, 2014, 11:12:03 pm »
Isn't it type mismatch? RBoardPosition.BoardPos is type RPolar while PolarNULL is type RDartPolar.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

lt.col.blair

  • New Member
  • *
  • Posts: 15
Re: cascaded record constants
« Reply #2 on: October 25, 2014, 02:22:59 pm »
Sorry, that was a typo in my post - happens, when you copy paste one part and type the other...
In my original code the BoardPos is also defined as RDartPolar.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: cascaded record constants
« Reply #3 on: October 25, 2014, 03:31:41 pm »
Well, i tried at least. Suspecting compiler just won't allow it? I went a bit further but it's giving me a vague "illegal expression", putting cursor ^ here:
(BoardPos: (Radius: PolarNULL.Radius^; Field: PolarNULL.Field);

Code: [Select]
  NRadius = single;
  NField = string;

  RDartPolar = record
    Radius: NRadius;
    Field: NField;
  end;

  RBoardPosition = record
    BoardPos: RDartPolar;
    RectPos: TPoint;
  end;

const
  radMissed = 1;
  fld20 = '20';
  PolarNULL: RDartPolar = (Radius: radMissed; Field: fld20);
  PointNULL: TPoint = (X: -1000; Y: -1000);

  //DartNULL: RBoardPosition = (BoardPos: PolarNULL; RectPos: PointNULL);
  DartNULL: RBoardPosition =
    (BoardPos: (Radius: PolarNULL.Radius; Field: PolarNULL.Field);
     RectPos: (x: PointNULL.x; y: PointNULL.y));

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: cascaded record constants
« Reply #4 on: October 25, 2014, 03:36:28 pm »
It has to do with writable constants that FPC supports. Although the default is not writable the compiler will not allow to use record constants as values for other record constants.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: cascaded record constants
« Reply #5 on: October 26, 2014, 10:27:46 am »
Probably the reason that the compiler does this is because of equality.

If a structured constant A could be added to a constant C (say as field B)   then C.B<>A since they are located on a different address.

 

TinyPortal © 2005-2018