Delphi getting value from field created at runtime

0

I create several runtime TRadioGroup:

Rdb1:= TRadioGroup.Create(Painel);

But with the same name "Rdb1". My question is how do I get the value of the field that was selected. I tried to do this:

Rdb1.OnExit := Validacao;

procedure TFCad_AnaliseDeTendencias.Validacao(Sender: TObject); 
begin
  if Rdb1.ItemIndex = 1 then
  begin
    showmessage('Acertou');
  end;

But since I have several "Rdb1" it only takes the value of the last created RadioGroup. Is there a way I can get the value of the RadioGroup that was "Clicked / Selected"?

    
asked by anonymous 16.02.2017 / 11:25

1 answer

7

As you explained, you do not have many components with the same name, but you are using the same variable to create these components. One way you do not have to worry about this, instead you can only use Sender of the procedure as follows:

procedure TFCad_AnaliseDeTendencias.Validacao(Sender: TObject); 
begin
  if TRadioGroup(Sender).ItemIndex = 1 then
  begin
    showmessage('Acertou');
  end;
end;

Note: It is important that when you create the component ( Create ) you determine a name single for it:

Rdb1.name := 'Radio' + controle;

Since controle is the variable you will need to define the logic to be generated.

    
16.02.2017 / 12:06