2
votes

Following on from my question Inno Setup disable component selection when a specific component is selected, I think there may be a way to get this to work without the problem of checked states set in code being permanent (though use of the Checked property) by instead using:

function CheckItem(const Index: Integer; const AOperation: TCheckItemOperation): Boolean;

in TNewCheckListBox, however I am having trouble getting the syntax correct. I am trying:

CheckItem(CompIndexSync, coUncheck) := Checked[CompIndexClient];

where the CompIndexes are constants assigned to the indexes for the component values. I get an Identifier Expected error at compile. Can someone advise how to correctly use this function and what I am doing wrong?

1

1 Answers

1
votes

The CheckItem member of the TNewCheckListBox class is a method of type function which updates the checked state by the AOperation operation and returns True if any changes were made to the state of the item at Index, or any of its children. Here is its prototype (source):

function TNewCheckListBox.CheckItem(const Index: Integer;
  const AOperation: TCheckItemOperation): Boolean;

The problem was that you were trying to assign a value to the function result. That's not what you can do in Pascal language in general. What you want to do with the item(s) is passed by the AOperation parameter. In pseudocode e.g.:

var
  CheckList: TNewCheckListBox;
  Operation: TCheckItemOperation;
begin
  ...
  if ShouldCheck then
    Operation := coCheck
  else
    Operation := coUncheck;

  if CheckList.CheckItem(ItemIndex, Operation) then
    MsgBox('An item has changed its state.', mbInformation, MB_OK);
end;