Author: Tomas Rutkauskas
How to set the item index in a TRadioGroup without firing the OnClick event
Answer:
1 2 procedure SetRadioItem(radiogroup: TRadioGroup; index: Integer);
3 var4 ev: TNotifyEvent;
5 begin6 ev := radiogroup.OnClick;
7 radiogroup.OnClick := nil;
8 radiogroup.ItemIndex := index;
9 radiogroup.Onclick := ev;
10 end;
A bit roundabout but it works. A checkbox could be treated similarly but I think
you can also set its state by sending a BM_SETCHECK to it without having the
OnClick event fire. This is untested:
11 12 procedure SetCheckbox(checkbox: TCheckbox; checked: Boolean);
13 const14 flags: array[boolean] of Integer = (BST_UNCHECKED, BST_CHECKED);
15 begin16 checkbox.Perform(BM_SETCHECK, flags[checked], 0);
17 end;