Using StringToColor in Inno Setup

Sla*_*ppy 0 delphi inno-setup

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?

Ser*_*yuz 6

正如安德烈亚斯在对这个问题的评论中提到的那样,没有内置功能.你可以自己制作,例如:

function StringToRGB(ColorStr: string): Integer;
var
  r, g, b: Integer;
begin
  r := StrToInt(Copy(ColorStr, 1, 3));
  g := StrToInt('$' + Copy(ColorStr, 4, 2));
  b := StrToInt('$' + Copy(ColorStr, 6, 2));
  Result := (r or (g shl 8) or (b shl 16));
end;
Run Code Online (Sandbox Code Playgroud)


如果你一直存储你的颜色$BBGGRR,你可以简单地转换它

StrToInt(ColorStr);
Run Code Online (Sandbox Code Playgroud)

  • @Slappy - 我认为你不需要演员.这是TColor是如何在[帕斯卡脚本](http://code.remobjects.com/p/pascalscript/source/tree/HEAD/Source/uPSC_graphics.pas#L205)暴露:`cl.addTypeS( 'TColor', '整数');` (2认同)