Reputation: 29
I used the RGB
function from Windows unit to generate random colors in VCL, and also used the TextOut
to write text in bitmap.
Now I need to write that in FireMonkey for Android
Uses windows;
R:=Random(256);
G:=Random(256);
B:=Random(256);
C:=RGB(R, G, B);
label1.Font.Color:=c;
Is there an equivalent for these in FireMonkey?
Upvotes: 2
Views: 181
Reputation: 2262
You might be looking for the function MakeColor
in System.UIConsts
.
Its defined like this:
function MakeColor(R, G, B: Byte; A: Byte = $FF): TAlphaColor;
So you can generate the color directly like this:
label1.Font.Color := MakeColor(Random(256),Random(256),Random(256));
Or to follow your example:
C: TAlphaColor;
begin
R:=Random(256);
G:=Random(256);
B:=Random(256);
C:=MakeColor(R, G, B);
label1.Font.Color:=c;
end;
Upvotes: 1
Reputation: 1245
Firemonkey uses TAlphaColor
colours. Use TAlphaColorRec
from the System.UITypes
unit to set the individual RGBA values of a colour, eg:
var C: TAlphaColorRec;
begin
C.A:=255; //Unless you also want random transparency!
C.R:=Random(256);
C.G:=Random(256);
C.B:=Random(256);
Label1.Font.Color:=C.Color;
end;
By the way, this won't actually change the font colour unless you also do the following:
Label1.StyledSettings:=Label1.StyledSettings-[TStyledSetting.FontColor];
When you change the font colour from the Object Inspector, it does that step for you. Without that step, you're telling Delphi to use the colour set in the style.
Upvotes: 6