Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/VCL/Standard Controls/TRadioGroup    [ Add a report in this area ]  
Report #:  101011   Status: Closed
List index out of bounds no RadioGroup1.Controls[xx].Enabled
Project:  Delphi Build #:  14.0.3593.25826
Version:    14.2 Submitted By:   Eduardo Fonseca
Report Type:  Feature Specification issue Date Reported:  11/14/2011 12:54:40 PM
Severity:    Commonly encountered problem Last Updated: 11/15/2011 5:18:03 PM
Platform:    All platforms Internal Tracking #:  
Resolution: As Designed (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
Added by Sysop
<<<<<
This report is related to QC#80578(Internal#271656).
>>>>>

List index out of bounds error occurs in RadioGroup.Controls[xx].Enabled

procedure TForm1.Button1Click(Sender: TObject);
begin
  Application.CreateForm( TForm2, Form2 );
  Form2.RadioGroup1.Buttons[04].Enabled := False;
  Form2.ShowModal;
end;

see Steps and Attachments
Steps to Reproduce:
=> In frmForm contains the following list:
RadioGroup1.Items.Add('1');
RadioGroup1.Items.Add('2');
RadioGroup1.Items.Add('3');
RadioGroup1.Items.Add('4');
RadioGroup1.Items.Add('5');
RadioGroup1.Items.Add('6');
RadioGroup1.Items.Add('7');
RadioGroup1.Items.Add('8');

Application.CreateForm( TfrmForm, frmForm );
frmForm.RadioGroup1.Controls[04].Enabled := False;

The error occurs  List index out of bounds


=> Inside the frmForm I put the statement

RadioGroup1.Controls[04].Enabled := False;

Without error List index out of bounds


Any reference to the RadioGroup error occurs:

frmForm.RadioGroup1.Buttons[04].Enabled := False;  ---> error:  List index out of bounds (4)
Workarounds
None
Attachment
Nova pasta.zip
Comments

Tomohiro Takahashi at 11/14/2011 5:20:56 PM -
TRadioGroup component uses lazy initialization.
So, if you acccess it before TForm is shown, please access Handle property of TRadioGroup as below.
----
procedure TForm1.Button1Click(Sender: TObject);
begin
  Application.CreateForm( TForm2, Form2 );
  Form2.RadioGroup1.Handle;  // <<------ added!!
  Form2.RadioGroup1.Buttons[04].Enabled := False;
  Form2.ShowModal;
end;
----

Eduardo Fonseca at 11/16/2011 10:23:41 AM -
ok it worked, but the correct would be the form's oncreate do this automatically handle loading

Server Response from: ETNACODE01