How to initialize checkbox value in installshield
How to set initial value of a check box (Checked/NotChecked) in InstallShield 2010.
I added CheckBox to the Form, during adding I let for creation of custom property (I named it ISCHECKED). I set Value to 1, so when checbox is checked then this property has开发者_运维百科 value equal to 1.
When I run installer I CheckBox is always checked and I want to have it unchecked, what should I do. I tried to modify this custom property and set value to different values in property manager but without luck. I know that when I click on the CheckBox it modifies this property value (I enable / disable other UI elements).
A checkbox is checked when its property is set and unchecked when the property is empty.
To make it unchecked by default, make sure that its property is not initialized to a value. Only associate the property to your checkbox, but do not set its value to "1".
I worked around this by creating a CheckBoxGroup with two checkboxes. One "Yes" and one "No" where "Yes" had the value 1 and "No" was value 0.
As I said in my comment this is still an issue in InstallShield 2018. Here's the workaround I came up with. I created two custom action scripts. One for translating from "0" and "1" to empty "" and "1" and another script for translating back to "0" and "1". I created custom actions TranslateChkBoxesZeroToEmptyAction and TranslateChkBoxesEmptyToZeroAction that call functions TranslateChkBoxesZeroToEmpty and TranslateChkBoxesEmptyToZero respectively.
I call TranslateChkBoxesZeroToEmptyAction In Behavior and Logic:Custom Actions and Sequences:Sequences:Installation:User Interface just after SetupCompleteSuccess and before AppSearch. I call TranslateChkBoxesEmptyToZeroAction just after MaintenanceWelcome and before SetupProgress.
So the affect is to convert "0" strings to empty"" before the dialog is opened and to convert empty "" to "0" after the dialog closes
===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;
FROM MICROSOFT LINK:
"This CheckBox_control is a two-state check box. To associate an integer or string property with this control, enter the property name into the Property column of the Control table. The selected state of the box sets the property either to the value specified in the Value column of the CheckBox table or to the initial value of the property specified in the Property table. If the property has no initial value, the checked state sets it to 1. The unselected state sets the property to null."
The terminology is confusing. What do they mean by "The selected state"? Do they mean the "Checked state"? And then it says it sets to EITHER the Value column or the initial [default] property value. Well which is it? It can't be both. From my experience the CHECKED state sets to the Value field of the CheckBox properties table and the UNCHECKED state always sets property to empty string "". The above text also fails to describe how the initial display state of the CHECKBOX is defined from the associated property by non-empty string = CHECKED and empty string = UNCHECKED. It only describes the action of setting the property on closing of dialog window.
I found the answer on: https://resources.flexera.com/web/pdf/archive/check.pdf
For any type of control, the initial value or state of the control is defined by the corresponding property's value. The value can be set in the Property table. In the case of a check box control, the initial state can be checked (selected) or unchecked (cleared): To have the check box initially checked, use the Property Manager view of the InstallShield environment to set the property (CHECKBOXPROP) to the same value you defined in the check box control's Value setting (1, in this example). To have the check box initially unchecked, delete the property (CHECKBOXPROP) from the Property Manager view.
This helped me at least for the VIEW.
In the View List under Behavior and Logic, click Property Manager.
Set the Value to 1 which property you want.
精彩评论