views:

164

answers:

1

I'm replacing several components in one of my forms with data-enabled versions, and it was a bit of a surprise when my new TDBRadioGroup didn't link up with the numeric field it was assigned to. Turns out that instead of going by the ItemIndex property, TDBRadioGroup's "value" is stored in a TStrings that you have to populate manually. I can understand that that would be useful in some cases, but when it's just linked to a numeric field, having to do something like this:

   for i := 0 to myRadioGroup.Items.Count - 1 do
      myRadioGroup.Values.Add(intToStr(i));

is kinda overkill. Does anyone know of a data-enabled radio group component that will use ItemIndex for its value parameter?

+1  A: 

You can specialize a TDBRadioGroup and add values By Index, I suggest you override the event procedure Loaded; override;

procedure TMyDBRadioGroup.Loaded; override;

var
  I: Integer;

begin
  inherited;
  Values.Clear;
  for i := 0 toItems.Count - 1 do
    Values.Add(intToStr(i));
end;
Cesar Romero
Problem is, that still has the same problem. It goes by IntToStr, and then has to convert those strings back to ints, and it just feels like a hack to me.
Mason Wheeler
You cant change the fact that Items ist stringlist, you should rewrite more parts of TDBRadioGroup if you are against convertions.
Cesar Romero
TStrings is like that, you can also re-do TDBRadioGroup by copying its source into a new file with a new name like TDBNumericRadioGroup, then you can do whatever you want.
Osama ALASSIRY