在Inno安装程序中使用StringToColor [英] Using StringToColor in Inno Setup
问题描述
我将我的颜色存储为我的颜色 $ RRGGBB'(String),我想使用Delphi函数StringToColor()将其转换为TColor,但如果在脚本中使用此功能,Inno Setup会显示错误。
如何告诉Inno安装程序使用此功能或如何将Inno中的String转换为使用此属性的TColor?
Sertac Akyuz的做法很好,但是在写了这个问题后我解决了几分钟,对不起:)
这是我的功能 - 还有一点点处理:
function StringToColor(Color:String):TColor;
var
RR,GG,BB:String;
Dec:整数;
begin
{将字符串颜色从$ RRGGBB更改为$ BBGGRR,然后转换为TColor}
if((Length(Color)<> 7)或(Color [1] >'$'))然后
结果:= $ 000000
else
begin
RR:= Color [2] + Color [3];
GG:=颜色[4] +颜色[5];
BB:=颜色[6] +颜色[7];
Dec:= StrToInt('$'+ BB + GG + RR);
结果:= TColor(Dec);
结束
结束
整个魔术功能
I would like to assign some color to label (TNewStaticText - property Color: TColor; read write;) on my form.
I have my color stored as '$RRGGBB' (String) and I would like to convert it to TColor using Delphi function StringToColor() but Inno Setup shows me an error if I use this function in script. How to tell Inno Setup to use this function or how to convert String to TColor in Inno to use it with this property?
Sertac Akyuz's approach is fine, but I solved this few minutes after writing this question, sorry :) This is my function - there is a little more handling:
function StringToColor(Color: String): TColor;
var
RR, GG, BB: String;
Dec: Integer;
begin
{ Change string Color from $RRGGBB to $BBGGRR and then convert to TColor }
if((Length(Color) <> 7) or (Color[1] <> '$')) then
Result := $000000
else
begin
RR := Color[2] + Color[3];
GG := Color[4] + Color[5];
BB := Color[6] + Color[7];
Dec := StrToInt('$' + BB + GG + RR);
Result := TColor(Dec);
end;
end;
The whole magic does function StrToInt() which converts String to Integer - but if you add '$' before string it treats the string as Hex number and it will be converted automatically to Decimal number. Result is Integer TColor created from that number.
这篇关于在Inno安装程序中使用StringToColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!