如何在installshield中初始化复选框值

时间:2011-07-29 17:52:37

标签: installshield

如何在InstallShield 2010中设置复选框的初始值(Checked / NotChecked)。

我在表单中添加了CheckBox,在添加期间我创建了自定义属性(我将其命名为ISCHECKED)。我将Value设置为1,因此当检查checbox时,此属性的值等于1.

当我运行安装程序时,我总是检查CheckBox,我想取消选中它,我该怎么办。我试图修改这个自定义属性并在属性管理器中将值设置为不同的值,但没有运气。我知道当我点击CheckBox时它会修改这个属性值(我启用/禁用其他UI元素)。

4 个答案:

答案 0 :(得分:10)

设置属性时检查复选框,当属性为空时取消选中。

要在默认情况下取消选中它,请确保其属性未初始化为值。仅将属性与您的复选框关联,但不要将其值设置为“1”。

答案 1 :(得分:2)

我通过创建一个带有两个复选框的CheckBoxGroup来解决这个问题。一个“是”和一个“否”,其中“是”的值为1,“否”为值0。

答案 2 :(得分:1)

正如我在评论中所说,这仍然是InstallShield 2018中的问题。这是我想出的解决方法。我创建了两个自定义动作脚本。一个用于将“ 0”和“ 1”转换为空的“”和“ 1”,另一个用于转换回“ 0”和“ 1”的脚本。我创建了自定义操作 TranslateChkBoxesZeroToEmptyAction TranslateChkBoxesEmptyToZeroAction ,分别调用函数 TranslateChkBoxesZeroToEmpty TranslateChkBoxesEmptyToZero

我在行为和逻辑:自定义操作和序列:序列:安装:用户界面中,在 SetupCompleteSuccess 之后和前,调用 TranslateChkBoxesZeroToEmptyAction > AppSearch 。我在 MaintenanceWelcome (维护欢迎)之后,在 SetupProgress 之前调用 TranslateChkBoxesEmptyToZeroAction

所以影响是在对话框打开之前将“ 0”字符串转换为空“”,而在对话框关闭之后将空“”字符串转换为“ 0”

=== setup.rul ====

export prototype ForceEmptyToZero(HWND, STRING);
export prototype ForceZeroToEmpty(HWND, STRING);
export prototype TranslateChkBoxesEmptyToZero(HWND);
export prototype TranslateChkBoxesZeroToEmpty(HWND);

// **********************************************************************
// function ForceEmptyToZero -- Convert "" to "0"
// 
// This function must be called on each CheckBox property after closing
// the dialog that contains the checkbox.  It converts empty "" string 
// to "0" in order to be compatible with InstallShield logic for checkboxes.
// 
// 2018Aug02jdn Created by Jon D. Newbill / www.bitworkssystems.com
// **********************************************************************
function ForceEmptyToZero(hMSI, propStr)
    STRING valStr;
    NUMBER strLen;
begin
    strLen = 100;
    MsiGetProperty(hMSI, propStr, valStr, strLen);
    // If not "1" then assume false and force to "0"
    if (valStr != "1") then
        valStr = "0";
        MsiSetProperty(hMSI, propStr, valStr);
    endif;
end;    

// **********************************************************************
// function ForceZeroToEmpty- Convert "0" to ""
// 
// This function must be called on each CheckBox property before opening
// the dialog that contains the checkbox.  It converts "0" string to 
// empty "" in order to be compatible with InstallShield logic for 
// checkboxes.
// 
// 2018Aug02jdn Created by Jon D. Newbill / www.bitworkssystems.com
// **********************************************************************
function ForceZeroToEmpty(hMSI, propStr)
    STRING valStr;
    NUMBER strLen;
begin
    strLen = 100;
    MsiGetProperty(hMSI, propStr, valStr, strLen);
    // If not "1" then assume false and force to empty string ""
    if (valStr != "1") then
        valStr = "";
        MsiSetProperty(hMSI, propStr, valStr);
    endif;
end;    



// **********************************************************************
// function TranslateChkBoxesZeroToEmpty -- Convert "0" to ""
// 
// This function must be called before the OptionSelection dialog is
// run.  This function converts all CheckBox properties from values of
// "0" or "1" to empty string "" or "1" respectively.  This is done to
// deal with an anomaly in the way InstallShield handles CheckBoxes
// assigned to properties.  Checkboxes are unchecked only when
// associated property is an empty string "" and checked for any other
// non-empty string.
// 
// https://stackoverflow.com/questions/6877011/how-to-initialize-checkbox-value-in-installshield
//
// So we must convert all "0" strings to "" empty string before the
// OptionSelection dialog runs and then convert all "" to "0" after the
// dialog closes.
// 
// 2018Aug02jdn Created by Jon D. Newbill / www.bitworkssystems.com
// **********************************************************************
function TranslateChkBoxesZeroToEmpty(hMSI)
    STRING valStr;
    NUMBER strLen;
begin
   ForceZeroToEmpty(hMSI,"TIMESTAMP");
   ForceZeroToEmpty(hMSI,"HIDECAPWIN");
   ForceZeroToEmpty(hMSI,"FINDVCP");
   ForceZeroToEmpty(hMSI,"LCDACCEPT");
   ForceZeroToEmpty(hMSI,"SERNUM");
   ForceZeroToEmpty(hMSI,"TOPWIN");
   ForceZeroToEmpty(hMSI,"ZOOM");
   ForceZeroToEmpty(hMSI,"ACCEPTCLOSE");
end;




// **********************************************************************
// function TranslateChkBoxesEmptyToZero -- Convert "" to "0"
// 
// This function must be called after the OptionSelection dialog closes.
// This function converts all CheckBox properties from values of empty
// string "" or "1" to "0" or "1" respectively.  This is done to deal
// with an anomaly in the way InstallShield handles CheckBoxes assigned
// to properties.  Checkboxes are unchecked only when associated
// property is an empty string "" and checked for any other non-empty
// string.
// 
// https://stackoverflow.com/questions/6877011/how-to-initialize-checkbox-value-in-installshield
//
// So we must convert all "0" strings to "" empty string before the
// OptionSelection dialog runs and then convert all "" to "0" after the
// dialog closes.
// 
// 2018Aug02jdn Created by Jon D. Newbill / www.bitworkssystems.com
// **********************************************************************
function TranslateChkBoxesEmptyToZero(hMSI)
    STRING valStr;
    NUMBER strLen;
begin
    ForceEmptyToZero(hMSI,"TIMESTAMP");
    ForceEmptyToZero(hMSI,"HIDECAPWIN");
    ForceEmptyToZero(hMSI,"FINDVCP");
    ForceEmptyToZero(hMSI,"LCDACCEPT");
    ForceEmptyToZero(hMSI,"SERNUM");
    ForceEmptyToZero(hMSI,"TOPWIN");
    ForceEmptyToZero(hMSI,"ZOOM");
    ForceEmptyToZero(hMSI,"ACCEPTCLOSE");
end;

MICROSOFT LINK开始:

“此CheckBox_control是一个两个状态的复选框。要将整数或字符串属性与此控件关联,请在“控件”表的“属性”列中输入属性名称。该框的选定状态用于设置属性如果是CheckBox表的“值”列中指定的值,或者是“属性”表中指定的属性的初始值,如果该属性没有初始值,则选中状态将其设置为1。空。”

术语令人困惑。 “选定状态”是什么意思?他们是指“已检查状态”吗?然后,它说将Value列或初始[default]属性值设置为EITHER。那是什么不能两者兼有。根据我的经验,CHECKED状态设置为CheckBox属性表的Value字段,而UNCHECKED状态始终将属性设置为空字符串“”。上面的文本也无法描述如何通过关联属性通过非空字符串= CHECKED和空字符串= UNCHECKED定义CHECKBOX的初始显示状态。它仅描述在关闭对话框窗口时设置属性的操作。

答案 3 :(得分:-1)

  1. 行为与逻辑下的查看列表中,点击 Property Manager

  2. 将值设置为1所需的属性。