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: : 7.0.8.1
Duplicate of:  None
Voting and Rating
Overall Rating: (7 Total Ratings)
4.43 out of 5
Total Votes: None
Description
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"!
Workarounds
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);
var
  I, Index: Integer;
begin
  if FValue <> Value then
  begin
    FInSetValue := True;
    try
      Index := -1;
      for I := 0 to Items.Count - 1 do
        if Value = GetButtonValue(I) then
        begin
          Index := I;
          Break;
        end;
//  Here use the work-around procedure
//      ItemIndex := Index;
      SetItemIndex(Index);
    finally
      FInSetValue := False;
    end;
    FValue := Value;
    Change;
  end;
end;

This is the added procedure:

procedure TDbRadioGroup.SetItemIndex(AIndex: integer);
var i: integer;
begin
  // 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
    begin
      // TGroupButton is a private type from ExtCtrls so use a TRadioButton
      // typecast
      if (Controls[i] is TRadioButton) and TRadioButton(Controls[i]).Checked
        then
      begin
        TCustomForm(Owner).ActiveControl := TRadioButton(Controls[i]);
        Break;
      end;
      dec(i);
    end;
  end;
end;
Attachment
2109.zip
Comments

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:

http://groups.google.com/groups?selm=328CACCA.46AE%40sunshine.net
http://groups.google.com/groups?selm=3b3026c1%241_1%40dnews
http://groups.google.com/groups?selm=3ce1bded%241_1%40dnews
http://groups.google.com/groups?selm=33c8c823.3517149%40news.interactive.net
http://groups.google.com/groups?selm=3921CE89.2CB98014%40airtel.net

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 borland.public.community 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:

http://groups.google.com/groups?selm=3db339fa%241%40newsgroups.borland.com

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

Server Response from: ETNACODE01