Now I am frustrated!
Have a single OnClick handler as this is supposed to trigger by clicking on either the checkbox or the item,
Box3.OnClick:= @Box3CK; To deal with the issues of clicking on the checkbox changing state, while clicking on the item does not visually change the checkbox state, I now have a custom TCheckListBox containing
BoxCheck : array of boolean that mirrors the state of the checkboxes. Solves that problem.
The start of the event handler,
very first line, has
writeln('box3 clicked on item ',Box3.ItemIndex); So I can see when
Box3CK gets fired.
In the event handler,
Box3CK, the test on the first item in the TCheckListBox is 'has the partition table changed since the backup'. The code:
with Box3 do //a set of if statements each exiting the procedure
begin
if Source = 0 then //it's the partition table - if changed it must be restored
begin
Checked[Source]:= true; //default assuming part table has changed
if CheckPartTable then //then okay to toggle
begin
Checked[Source]:= not BoxCheck[Source];
BoxCheck[Source]:= Checked[Source]; //save the new state
end
else BoxCheck[Source]:= true; //must be restored
//check to see if there is an extended partition, its state = state of part table
//for i:= 1 to Count - 1 do if pos(ExtendStr,Items[i]) > 0 then Checked[i]:= Checked[Source];
exit;
end;
Tested in a scenario where the partition table has changed since the backup so it MUST be restored = checkbox should always be true.
CheckPartTable generates a message dialog if the part table has changed warning the user.
Testing - compile, run, select backup, box3 get populated (default all checkboxes = true):
- Click on checkbox for item 0, event handler fires, message displayed, checkbox stays true = correct behaviour.
- Click on checkbox a second time - event handler not fired, but checkbox showing false - see screenshot. This should not happen - it should fire the event handler.
- Subsequent clicks on the checkbox - it behaves as it should, Box3CK fired, checkbox set true.
- Clicking on the item, not the checkbox = behaves as it should.
To fix the problem, tried setting
Box3.OnClickCheck:= @Box3CK as well as using
OnClick. Seems to solve the problem, but now, of course, the handler is fired twice when you click on the checkbox = warning message displayed twice to user
Yes it is a bit of a rant, but not sure how to proceed.