Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Database/Data Aware Controls/TDBRadioGroup    [ Add a report in this area ]  
Report #:  2109   Status: Closed
TDbRadiogroup unattended changes fielddata
Project:  Delphi Build #:  6.240
Version:    7.0 Submitted By:   Arjen de Ruijter
Report Type:  Crash / Data loss / Total failure Date Reported:  8/15/2002 2:03:15 PM
Severity:    Serious / Highly visible problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   93528
Resolution: Fixed (Resolution Comments) Resolved in Build: :
Duplicate of:  None
Voting and Rating
Overall Rating: (7 Total Ratings)
4.43 out of 5
Total Votes: None
When a dbradiogroup button has focus, but the dataset caused another button to be checked, then deactivating/activating the form causes the focused button-value to be put into the dataset and overwrites the current value!
Steps to Reproduce:
- Compile and run the attached test application.
- check radiobutton "one". The button will be selected and a timer will be started.
- When the timer fires the value in the dataset will be set to "two" and posted.
- Now deactivate and activate the application.
- Look at the radiogroup and post! The record in the dataset is as a result of the bug changed back to the old (not wanted) value "one"!
My workaround is not a easy one, it needs to recompile the vcl, or make a complete copy of the component, because there are no override possibilities, these procedures are changed:

In SetValue not directly set ItemIndex but use another procedure SetItemIndex which works around the problem.

procedure TDBRadioGroup.SetValue(const Value: string);
  I, Index: Integer;
  if FValue <> Value then
    FInSetValue := True;
      Index := -1;
      for I := 0 to Items.Count - 1 do
        if Value = GetButtonValue(I) then
          Index := I;
//  Here use the work-around procedure
//      ItemIndex := Index;
      FInSetValue := False;
    FValue := Value;

This is the added procedure:

procedure TDbRadioGroup.SetItemIndex(AIndex: integer);
var i: integer;
  // when a focused radiobutton regains focused it gets checked!!
  // and changes the data!
  // so when one of my buttons has focus always change the focus to the newly checked!
  if AIndex=ItemIndex then Exit;
  ItemIndex := AIndex;
  if (Owner is TCustomForm) and (TCustomForm(Owner).ActiveControl<>nil) and
    (TCustomForm(Owner).ActiveControl.Parent=Self) then
  begin  // one of my buttons has focus
    i := ControlCount-1;
    while i>=0 do
      // TGroupButton is a private type from ExtCtrls so use a TRadioButton
      // typecast
      if (Controls[i] is TRadioButton) and TRadioButton(Controls[i]).Checked
        TCustomForm(Owner).ActiveControl := TRadioButton(Controls[i]);

Arjen de Ruijter at 8/19/2002 9:17:56 AM -
Nobody has given a reaction, why not? it seems to me as a real problem that already exists for a long time (I found a reference to it from 1996!).
I've been looking around and found several other old occurences from the same bug:

Why is it that nobody seems to matter and why is there after six years no real solution for this.

In my opinion the solution is that when a 'child' button from a TDBRadiogroup gets checked because of a data-change-event the focus must be set accordingly. (see my workaround)

Kristofer Skaug at 8/22/2002 2:11:42 AM -
Some of the core report raters have either stopped rating (due to disputes) or have been away on holidays. See also discussions in the newsgroup regarding the rating discussions.

Arjen de Ruijter at 4/16/2003 4:55:12 AM -
After almost eight months of silence no recognition or something from someone for this bug,

please read this newsgroup-post from oktober 2002:

This bug seems very 'nasty' but nobody seems to matter??

Server Response from: ETNACODE01