Forum > General

cascaded record constants

(1/2) > >>

lt.col.blair:
Hi,

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

My structures are like this:

--- Code: ---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.'

--- End code ---

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

Blaazen:
Isn't it type mismatch? RBoardPosition.BoardPos is type RPolar while PolarNULL is type RDartPolar.

lt.col.blair:
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:
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: ---  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));
--- End code ---

taazz:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version