Recent

Author Topic: [SOLVED] RadioGroup not accepting new value  (Read 4941 times)

march

  • New Member
  • *
  • Posts: 17
[SOLVED] RadioGroup not accepting new value
« on: March 05, 2012, 12:57:00 am »
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.
« Last Edit: March 06, 2012, 02:25:28 am by march »

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: RadioGroup not accepting new value
« Reply #1 on: March 05, 2012, 10:44:15 am »
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).

1.0/2.6.0  XP SP3 & OS X 10.6.8

Bart

  • Hero Member
  • *****
  • Posts: 5706
    • Bart en Mariska's Webstek
Re: RadioGroup not accepting new value
« Reply #2 on: March 05, 2012, 11:42:33 am »
This was fixed in trunk.

Bart

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4695
  • I like bugs.
Re: RadioGroup not accepting new value
« Reply #3 on: March 05, 2012, 12:02:44 pm »
This 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
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

march

  • New Member
  • *
  • Posts: 17
Re: RadioGroup not accepting new value
« Reply #4 on: March 05, 2012, 06:50:50 pm »
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

  • Hero Member
  • *****
  • Posts: 5706
    • Bart en Mariska's Webstek
Re: RadioGroup not accepting new value
« Reply #5 on: March 05, 2012, 10:45:49 pm »
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
« Last Edit: March 05, 2012, 10:49:48 pm by Bart »

march

  • New Member
  • *
  • Posts: 17
Re: RadioGroup not accepting new value
« Reply #6 on: March 06, 2012, 02:18:00 am »
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.

 

TinyPortal © 2005-2018