在Inno安装程序中使用StringToColor [英] Using StringToColor in Inno Setup

查看:180
本文介绍了在Inno安装程序中使用StringToColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我将我的颜色存储为我的颜色 $ 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);
结束
结束

整个魔术功能 StrToInt()将String转换为整数 - 但是如果在字符串之前添加'$',则将该字符串视为十六进制数,并将自动转换为十进制数。结果是从该号码创建的整数TColor。


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆