Search code examples
delphidelphi-xe2firemonkey

Why do I get 'Undeclared identifier' when specifying a runtime color in a FireMonkey Delphi application?


I'm playing with my first FireMonkey app. I've created a grid of TRectangle's and now I want to set the color of each one programmatically. I've done:

procedure TForm9.Button2Click(Sender: TObject);
var
  C : TRectangle;
  I : integer;
//const
//  Alpha = TAlphaColor($FF000000);
//  Red = Alpha or TAlphaColor($FF0000);

begin
  for I := 0 to ScaledLayout1.ChildrenCount-1 do
    begin
    If ScaledLayout1.Children[I] is TRectangle then
      begin
      C := Trectangle(ScaledLayout1.Children[I]);
      C.Fill.Color := Red; <<< ERROR
      C.Fill.Kind := bkSolid <<< ERROR;
      end;
    end;
end;

I get compiler errors 'unidentified identifier' at '<< ERROR' trying to assign the constants 'Red' and 'bkSolid'. If I go into System.UITypes and copy out 'Red' as in my commented out 'const' above, it all works. Yet 'System.UITypes' is in my uses list. Trying C.Fill.Color := TAlphaColor.Red does not work either. What might I be doing wrong please? Thanks.


Solution

  • TAlphaColor is type of cardinal, not an enum or const. TAlphaColors.Red is working (note the 's' by AlphaColorS) or claRed. By bkSolid use TBrushKind.bkSolid