LoginSignup
0
0

More than 5 years have passed since last update.

Inno Setup Script の三項演算子ぽいやつ

Posted at

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;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0