2016-08-19 106 views
1

我想在Inno Setup Pascal脚本中将HTML十六进制颜色转换为TColor将十六进制颜色转换为Inno Setup中的TColor Pascal脚本

我试图从Convert Inno Setup Pascal Script TColor to HTML hex colour倒车功能ColorToWebColorStr,但我可能需要一个像RGBToColor一个函数来获取结果作为TColor#497AC2 HTML十六进制颜色转换

例子应该返回为TColor$C27A49 输入应该是HTML颜色字符串表示形式,输出应该是TColor

UPDATE

当我使用从VCL Windows单元下面的函数在创新安装,TForm.Color显示为红色。

const 
    COLORREF: TColor; 

function RGB(R, G, B: Byte): COLORREF; 
begin 
    Result := (R or (G shl 8) or (B shl 16)); 
end; 

DataChecker.Color := RGB(73, 122, 194); 

颜色我预计在TForm.Color是:

<html> 
 
<body bgcolor="#497AC2"> 
 
<h2>This Background Colour is the Colour I expected instead of Red.</h2> 
 
</body> 
 
</html>

另外,我也想知道为什么红色将返回此处(表格显示红色),而不是预计半浅蓝.........


我想使用的转换为:提前

#define BackgroundColour "#497AC2" 

procedure InitializeDataChecker; 
... 
begin 
... 
    repeat 
    ShellExec('Open', ExpandConstant('{pf64}\ImageMagick-7.0.2-Q16\Convert.exe'), 
     ExpandConstant('-size ' + ScreenResolution + ' xc:' '{#BackgroundColour}' + ' -quality 100% "{tmp}\'+IntToStr(ImageNumber)+'-X.jpg"'), '', SW_HIDEX, ewWaitUntilTerminated, ErrorCode); 
...  
    until FileExists(ExpandConstant('{tmp}\'+IntToStr(ImageNumber)+'.jpg')) = False; 
... 
end; 

... 
DataChecker := TForm.Create(nil); 
{ ---HERE IT SHOULD BE RETURNED AS `$C27A49`--- } 
DataChecker.Color := NewFunction({#BackgroundColour}) 

感谢。

+0

你会用什么样的功能? –

+0

什么是DataChecker? –

+0

这是一个'TForm',用于处理在安装过程中显示的一些图像。看到我更新的问题........... – Blueeyes789

回答

1
function RGB(r, g, b: Byte): TColor; 
begin 
    Result := (Integer(r) or (Integer(g) shl 8) or (Integer(b) shl 16)); 
end; 

function WebColorStrToColor(WebColor: string): TColor; 
begin 
    if (Length(WebColor) <> 7) or (WebColor[1] <> '#') then 
    RaiseException('Invalid web color string'); 

    Result := 
    RGB(
     StrToInt('$' + Copy(WebColor, 2, 2)), 
     StrToInt('$' + Copy(WebColor, 4, 2)), 
     StrToInt('$' + Copy(WebColor, 6, 2))); 
end; 

你RGB功能不起作用,因为它似乎Pascal脚本(与德尔福)不会隐式转换/扩大ByteIntegershl操作。所以你必须明确地做。

+0

再次感谢您......... ;-)这对Ansi和Unicode Inno安装程序版本都能起作用吗? – Blueeyes789

+0

我只测试过Unicode版本。但我没有看到它不应该在Ansi版本中工作的原因。 –

+0

我使用'Log(IntToStr(WebColorStrToColor('#497AC2')))函数在日志中返回'TColor'作为字符串,如'12745289';'.........出错了这里? – Blueeyes789

相关问题