0
votes

In an FMX component, I have this definition:

published
  property BackgroundColor: TColor read fBackgroundColor write fBackgroundColor;
end;

If BackgroundColor is set to a const, like clRed, then I get an EReadError "Error reading BackgroundColor: Invalid property value".

It works with a normal value, like $00FF8000. So why does the Object inspector let you select a const???

The workaround is to declare the property as TAlphaColor, but that means another conditional define in my combined VCL/FMX unit.

Is there any other way I can keep the property as TColor?

Delphi 10.3.2

1
Which class does the BackgroundColor belong to? What is the type of this BackgroundColor? I believe that the type is TAlphaColor any you can not assign a TColor to a TAlphaColor. - Schneider Infosystems Ltd
It descends from TControl which does not have a BackgroundColor property. It is a field fBackgroundColor: TColor; - Zax

1 Answers

1
votes

I assume you mix TColors with TColor. Both are defined in System.UITypes:

TColor = -$7FFFFFFF-1..$7FFFFFFF;

TColors = TColorRec;
TColorRec = record ...

From Vcl.Graphics:

clRed = TColors.Red;

Maybe the following function could help you to convert the types

function AlphaColorToColor(const Color: TAlphaColor): TColor;

Unfortunately, No function ColorToAlphaColor is available in System.UITypes.

Uwe Raabe has published an own solution in the DelphiPraxis forum for this purpose:

function ColorToAlphaColor(Value: TColor): TAlphaColor;
var
  CRec: TColorRec;
  ARec: TAlphaColorRec;
begin
  CRec.Color := Value;
  ARec.A := CRec.A;
  ARec.B := CRec.B;
  ARec.G := CRec.G;
  ARec.R := CRec.R;
  Result := ARec.Color;
end;

See also here Convert TColor in TAlphaColor