🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.vcl.components.using.win32
6 messages
6 total messages Started by newsgroups.borland.com Wed, 23 Jul 2008 17:19
VCL TRadioButton issue ...
#71
Author: newsgroups.borland.com
Date: Wed, 23 Jul 2008 17:19
63 lines
3536 bytes
Hi,

Although I am using Delphi since Delphi1 I didn't realize this strange 
issue with RadioButtons until now, although I found some referencing 
about on google, coming from 2003.

Issue is with TRadioButtons (but applies also on TRadioGroup) and how 
you control them run-time from the code.

Here goes example...

I have a main form (form1) from which I open (showmodal) a secondary 
form (form2) - within the same program/exe (although it applies on 
packages/dlls containing forms too).
On form2 there are two radiobuttons, radiobutton1 having checked := true.

So, I simply:

1) run the program (form1 opens)
2) click the button on form1 which opens form2 (form2.showmodal)
3) there are two radiobuttons, with radiobutton1.checked = true
4) I click on RadioButton2, which becomes checked (unchecking 
radiobutton1, at least visually)
5) I close the form2 (clicking on X icon), so the form2 closes/hides 
(does not get freed)
6) now on form1 I click another button which sets 
form2.radiobutton1.checked to true (which should uncheck radiobutton2 on 
  form2) and I reopen/showmodal the form2

-> BUT instead of having the radiobutton1.checked = true I still have 
the radiobutton2.checked ?!

Now, what I foundis that you cannot set the radiobutton.checked 
programatically runtime (it will show correctly but will NOT behave 
properly) until you do not ALSO set the radiobutton or any other control 
on the form to have focus (or by setting focus, or by using 
form.activecontrol := control).

Now question bothering me is:

1) Why the radiobutton.checked = true does NOT work from the code UNLESS 
you set the radiobutton or any other CONTROL on the form to have the 
focus, or you simple at the other control like button (I am forced to do 
something like form2.activecontrol := form2.radiobutton1; 
form2.radiobutton1.checked := true in order to have form2 opening with 
default radiobutton1 checked regardless of what was clicked/checked the 
last time you closed the form2)

2) Is this Delphi/VCL or more generally speaking a Windows/Controls issue
3) Noone, except the few in the past (looking at google groups), didn't 
realize/spoke about that issue?

p.s.
-I am using CodeGear RAD Studio 2007 with all the patches applied, but I 
see it was mentioned in the past with Delphi3 as well.

-the issue appears regardless of how you set the tabstop for radiobuttons

-when you click the radio button (or you 'select' it with keyboard it 
gets tabstop automatically set to TRUE although it might be set to FALSE ?!

Thanks and Kind Regards,
Boro
Re: VCL TRadioButton issue ...
#75
Author: Remy Lebeau (TeamB)
Date: Wed, 23 Jul 2008 20:06
56 lines
2992 bytes
"newsgroups.borland.com" <zlatibor.urosevic@yahoo.it> wrote in message 
news:4887683d$1@newsgroups.borland.com...

> I close the form2 (clicking on X icon), so the form2 closes/hides (does 
> not get freed)

In other words, RadioButton2 is the last control with input focus when the 
form is closed.

> now on form1 I click another button which sets form2.radiobutton1.checked
> to true (which should uncheck radiobutton2 on  form2) and I
> reopen/showmodal the form2
>
> -> BUT instead of having the radiobutton1.checked = true I still
> have the radiobutton2.checked ?!

Input focus is still set to be on RadioButton2, so when the form is 
re-shown, RadioButton2 becomes activated, and thus becomes checked.

> Now, what I foundis that you cannot set the radiobutton.checked 
> programatically runtime

Yes, you can.

> it will show correctly but will NOT behave properly

In what way?

> Why the radiobutton.checked = true does NOT work from the
> code UNLESS you set the radiobutton or any other CONTROL
> on the form to have the focus

You just answered your own question.  It is all about input focus.  When a 
radio button receives focus, it automatically becomes checked.  The same 
thing happens if you put a bunch of TRadioButton controls on a panel and 
then tab around them at runtime, or put a bunch of items in a TRadioGroup 
and then use arrow keys at runtime.

> I am forced to do something like form2.activecontrol := 
> form2.radiobutton1;
> form2.radiobutton1.checked := true in order to have form2 opening
> with default radiobutton1 checked regardless of what was clicked/checked
> the last time you closed the form2

Or, set ActiveControl := nil instead so that no controls receive focus right 
away.

> Is this Delphi/VCL or more generally speaking a Windows/Controls issue

You are not clearing out the ActiveControl when closing the form, so 
RadioButton2 receives focus again when re-showing the form.  The RadioButton 
automatically becomes checked when it receives focus.


Gambit 
Re: VCL TRadioButton issue ...
#76
Author: Zlatibor Boro Urosevic
Date: Wed, 23 Jul 2008 21:25
100 lines
5336 bytes
Peter/Remy, thank you both for your comments...

Peter,
As a 'programmer', ;o), I actually do follow a common incapsulaltion 
practices, using my own form's public properties and their 
getters/setters to 'communicate' with objects from the 'outside' world, 
which in turn are setting the corresponding form's private radiobuttons 
checked states (or other controls 'states') depending on what has to be 
done.

However, when I ran into this radiobutton focus/checked problem I also 
created a simple 2-forms prototype to obtain more details about it, 
following good 'RADers' practices (quick and easy), so to understand how 
setting checked states behave, when called within as well as from the 
outside of the form.

My only consideration would be, related to a Delphi (2007) help info 
about radiobutton.checked state, that setting the radiobutton's checked 
property will NOT ALWAYS set correctly the radio button's 'state' as its 
state also depends on the control's focus state as well.

(as Remy mentioned, you can set radiobutton's checked property to true, 
but if radiobutton does not get focus as well (or any other control on 
the form btw) it will not set the state properly, hence, misleading the 
end-user 'programmer' when saying within D2007 help ...

"Read Checked to determine whether the radio button is selected. Set 
Checked to true to select the radio button and deselect all other radio 
buttons in the same container. Set Checked to false to deselect the 
radio button, leaving no radio button in the group selected.
"
).

Kind Regards,
Boro


> Hi,
> 
> Although I am using Delphi since Delphi1 I didn't realize this strange 
> issue with RadioButtons until now, although I found some referencing 
> about on google, coming from 2003.
> 
> Issue is with TRadioButtons (but applies also on TRadioGroup) and how 
> you control them run-time from the code.
> 
> Here goes example...
> 
> I have a main form (form1) from which I open (showmodal) a secondary 
> form (form2) - within the same program/exe (although it applies on 
> packages/dlls containing forms too).
> On form2 there are two radiobuttons, radiobutton1 having checked := true.
> 
> So, I simply:
> 
> 1) run the program (form1 opens)
> 2) click the button on form1 which opens form2 (form2.showmodal)
> 3) there are two radiobuttons, with radiobutton1.checked = true
> 4) I click on RadioButton2, which becomes checked (unchecking 
> radiobutton1, at least visually)
> 5) I close the form2 (clicking on X icon), so the form2 closes/hides 
> (does not get freed)
> 6) now on form1 I click another button which sets 
> form2.radiobutton1.checked to true (which should uncheck radiobutton2 on 
>  form2) and I reopen/showmodal the form2
> 
> -> BUT instead of having the radiobutton1.checked = true I still have 
> the radiobutton2.checked ?!
> 
> Now, what I foundis that you cannot set the radiobutton.checked 
> programatically runtime (it will show correctly but will NOT behave 
> properly) until you do not ALSO set the radiobutton or any other control 
> on the form to have focus (or by setting focus, or by using 
> form.activecontrol := control).
> 
> Now question bothering me is:
> 
> 1) Why the radiobutton.checked = true does NOT work from the code UNLESS 
> you set the radiobutton or any other CONTROL on the form to have the 
> focus, or you simple at the other control like button (I am forced to do 
> something like form2.activecontrol := form2.radiobutton1; 
> form2.radiobutton1.checked := true in order to have form2 opening with 
> default radiobutton1 checked regardless of what was clicked/checked the 
> last time you closed the form2)
> 
> 2) Is this Delphi/VCL or more generally speaking a Windows/Controls issue
> 3) Noone, except the few in the past (looking at google groups), didn't 
> realize/spoke about that issue?
> 
> p.s.
> -I am using CodeGear RAD Studio 2007 with all the patches applied, but I 
> see it was mentioned in the past with Delphi3 as well.
> 
> -the issue appears regardless of how you set the tabstop for radiobuttons
> 
> -when you click the radio button (or you 'select' it with keyboard it 
> gets tabstop automatically set to TRUE although it might be set to FALSE ?!
> 
> Thanks and Kind Regards,
> Boro
Re: VCL TRadioButton issue ...
#77
Author: Zlatibor Boro Urosevic
Date: Wed, 23 Jul 2008 21:25
100 lines
5319 bytes
Peter/Remy, thank you both for your comments...

Peter,
As a 'programmer', ;o), I actually do follow a common incapsulaltion 
practices, using my own form's public properties and their 
getters/setters to 'communicate' with objects from the 'outside' world, 
which in turn are setting the corresponding form's private radiobuttons 
checked states (or other controls 'states') depending on what has to be 
done.

However, when I ran into this radiobutton focus/checked problem I also 
created a simple 2-forms prototype to obtain more details about it, 
following good 'RADers' practices (quick and easy), so to understand how 
setting checked states behave, when called within as well as from the 
outside of the form.

My only consideration would be, related to a Delphi (2007) help info 
about radiobutton.checked state, that setting the radiobutton's checked 
property will NOT ALWAYS set correctly the radio button's 'state' as its 
state also depends on the control's focus state as well.

(as Remy mentioned, you can set radiobutton's checked property to true, 
but if radiobutton does not get focus as well (or any other control on 
the form btw) it will not set the state properly, hence, misleading the 
end-user 'programmer' when saying within D2007 help ...

"Read Checked to determine whether the radio button is selected. Set 
Checked to true to select the radio button and deselect all other radio 
buttons in the same container. Set Checked to false to deselect the 
radio button, leaving no radio button in the group selected.
"
).

Kind Regards,
Boro


> Hi,
> 
> Although I am using Delphi since Delphi1 I didn't realize this strange 
> issue with RadioButtons until now, although I found some referencing 
> about on google, coming from 2003.
> 
> Issue is with TRadioButtons (but applies also on TRadioGroup) and how 
> you control them run-time from the code.
> 
> Here goes example...
> 
> I have a main form (form1) from which I open (showmodal) a secondary 
> form (form2) - within the same program/exe (although it applies on 
> packages/dlls containing forms too).
> On form2 there are two radiobuttons, radiobutton1 having checked := true.
> 
> So, I simply:
> 
> 1) run the program (form1 opens)
> 2) click the button on form1 which opens form2 (form2.showmodal)
> 3) there are two radiobuttons, with radiobutton1.checked = true
> 4) I click on RadioButton2, which becomes checked (unchecking 
> radiobutton1, at least visually)
> 5) I close the form2 (clicking on X icon), so the form2 closes/hides 
> (does not get freed)
> 6) now on form1 I click another button which sets 
> form2.radiobutton1.checked to true (which should uncheck radiobutton2 on 
>  form2) and I reopen/showmodal the form2
> 
> -> BUT instead of having the radiobutton1.checked = true I still have 
> the radiobutton2.checked ?!
> 
> Now, what I foundis that you cannot set the radiobutton.checked 
> programatically runtime (it will show correctly but will NOT behave 
> properly) until you do not ALSO set the radiobutton or any other control 
> on the form to have focus (or by setting focus, or by using 
> form.activecontrol := control).
> 
> Now question bothering me is:
> 
> 1) Why the radiobutton.checked = true does NOT work from the code UNLESS 
> you set the radiobutton or any other CONTROL on the form to have the 
> focus, or you simple at the other control like button (I am forced to do 
> something like form2.activecontrol := form2.radiobutton1; 
> form2.radiobutton1.checked := true in order to have form2 opening with 
> default radiobutton1 checked regardless of what was clicked/checked the 
> last time you closed the form2)
> 
> 2) Is this Delphi/VCL or more generally speaking a Windows/Controls issue
> 3) Noone, except the few in the past (looking at google groups), didn't 
> realize/spoke about that issue?
> 
> p.s.
> -I am using CodeGear RAD Studio 2007 with all the patches applied, but I 
> see it was mentioned in the past with Delphi3 as well.
> 
> -the issue appears regardless of how you set the tabstop for radiobuttons
> 
> -when you click the radio button (or you 'select' it with keyboard it 
> gets tabstop automatically set to TRUE although it might be set to FALSE ?!
> 
> Thanks and Kind Regards,
> Boro
Re: VCL TRadioButton issue ...
#79
Author: Peter Below (TeamB)
Date: Thu, 24 Jul 2008 17:54
20 lines
1795 bytes
Zlatibor Boro Urosevic wrote:

> My only consideration would be, related to a Delphi (2007) help info
> about radiobutton.checked state, that setting the radiobutton's
> checked property will NOT ALWAYS set correctly the radio button's
> 'state' as its state also depends on the control's focus state as
> well.

But of course it does set the radiobuttons check state correctly. You
are just doing something after that which causes the check state to
move. Certainly that's not the radiobuttons fault. The property will
work perfectly well if you are setting the check state while the form
the button sits on is visible and active <g>.

-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
Re: VCL TRadioButton issue ...
#81
Author: Zlatibor Boro Urosevic
Date: Thu, 24 Jul 2008 18:39
34 lines
2584 bytes
Mmmm, not sure I would agree completely.

As from my example, ...

...when having the two radiobuttons on the form (rb1 and rb2) and I 
click on rb2 so it is checked by mouse and it actuallly gains focus, 
calling the RB1.Checked from the code WITHOUT refocusing rb2 to another 
control (for example when closing the form, form.close) I would expect 
RB1 to remain checked after that and that RB1 itself 'fixes' eventual 
focus issues, focusing itself if not focused already, as if it was 
clicked on or selected by keyboard, which it does NOT now (leaving the 
possibility to form to refocus the last focued radiobutton - rb2 in this 
case, through activecontrol, when eventually reopenning the form (close 
 > showmodal, which is misleading in my opinion).

Kind Regards,
Boro


Peter Below (TeamB) ha scritto:
> Zlatibor Boro Urosevic wrote:
> 
>> My only consideration would be, related to a Delphi (2007) help info
>> about radiobutton.checked state, that setting the radiobutton's
>> checked property will NOT ALWAYS set correctly the radio button's
>> 'state' as its state also depends on the control's focus state as
>> well.
> 
> But of course it does set the radiobuttons check state correctly. You
> are just doing something after that which causes the check state to
> move. Certainly that's not the radiobuttons fault. The property will
> work perfectly well if you are setting the check state while the form
> the button sits on is visible and active <g>.
> 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads