Inno Setup のスクリプトは便利だけど、微妙に Pascal や delphi の機能が足りないのが残念です。
Delphiの 三項演算子ぽい IfThen()
も当然ない.
http://delphi.about.com/library/rtl/blrtlIfThen.htm
仕方がないので、それっぽいのを作って満足するしかないです。Inno Setup Script にもオーバーロードあればいいのに。
// prototype
function IfThenStr(cond : boolean; a, b : string): String; forward;
function IfThenInt(cond : boolean; a, b : Integer): Integer; forward;
// function
function IfThenStr(cond : boolean; a, b : string): String;
begin
Result := b
if cond then
Result := a;
end;
function IfThenInt(cond : boolean; a, b : Integer): Integer;
begin
Result := b
if cond then
Result := a;
end;
使い方は、こんな感じでしょうか。
function initializeSetup() : boolean;
var
str : string;
i, x, y : Integer;
begin
x := 10; y := 11;
str := IfThenStr(x > y, 'true string', 'false string');
i := IfThenInt(x > y, 0, 1);
end;