[SOLVED] RadioGroup not accepting new value lazarus / 31-LCL ---------------------------------------------------------------------- march · 2012-03-04 23:57 Here is something that seems so wrong, I must be overlooking something. My radio buttons work as expected when I click on the buttons to change a global variable. But when the variable is set by code elsewhere, the radio group does not reflect the new value when the form is opened. Here is a simple example. TestRadio is a global word set to 0 or 1. There is one control in FormTestRadio, RadioGroup1 with Items "zero" and "one". Default index is -1. TestRadio is initially 0. On first open of the form, the item shows "zero" correctly. TestRadio is then set by code to 1 in another unit. When the form is opened again, the item is still "zero" and after closing, TestRadio has been reset to 0. So the procedure FormShow appears to not be effective after the first open of the form. Code: [Select]var   FormTestRadio: TFormTestRadio; implementation procedure TFormTestRadio.FormShow(Sender: TObject); begin  RadioGroup1.ItemIndex := TestRadio; end; procedure TFormTestRadio.FormClose(Sender: TObject;                                    var CloseAction: TCloseAction); begin  TestRadio := RadioGroup1.ItemIndex; end; When TestRadio is initially 1, at first "one" shows correctly. As before, any further changes outside the form are not picked up. Using Lazarus 9.30 in WindowsXP. ---------------------------------------------------------------------- Arbee · 2012-03-05 09:44 I haven't checked it in detail, but maybe it is an idea to put the assignment of the radio button in an "onActivate" event.  That fires every time the window becomes active (which includes the situation where it is opened). ---------------------------------------------------------------------- Bart · 2012-03-05 10:42 This was fixed in trunk. Bart ---------------------------------------------------------------------- JuhaManninen · 2012-03-05 11:02 Quote from: Bart on March 05, 2012, 11:42:33 amThis was fixed in trunk. Is it fixed? There is a new bug report which claims it happens also with trunk.   http://bugs.freepascal.org/view.php?id=21417 Could you Bart take a look. Juha ---------------------------------------------------------------------- march · 2012-03-05 17:50 The new bug report is a different issue. It is about click events on form re-activation. A fix which I think Bart is refering to, also seems to be about click events. My radio group does not use click events. Is it the conclusion that what I am seeing is a bug, and what I am doing should work? ---------------------------------------------------------------------- Bart · 2012-03-05 21:45 The fix I'm referring to is about not being able to set TRadioGroup.ItemIndex to any other value then 0 whenshowing a form. This was fixed, but I cannot find the issue or revision. A workaround for the issue was: set the forms ActiveControl to a control on the form. IIRC this bug was only triggered if ActiveControl was unassigned on the form. [Edit] It's bugreport #20510 [/Edit] Bart ---------------------------------------------------------------------- march · 2012-03-06 01:18 I tried setting an active control as the first statement in FormShow. FormTestRadio.ActiveControl := RadioGroup1; It worked! Now the radio group accepts any value that has been preset. Thanks very much, Bart.