Mega Code Archive

 
Categories / Delphi / VCL
 

Access the controls of a TRadioGroup

Title: access the controls of a TRadioGroup? { Die Eigenschaft Controls führt alle untergeordneten Komponenten eines Steuerelements (Hier z.B TRadioGroup) auf. Controls ist hilfreich, wenn auf die untergeordneten Steuerelemente mit einer Zahl und nicht mit ihrem Namen Bezug genommen werden soll. So kann Controls beispielsweise verwendet werden, um in einer TRadioGroup Eigenschaften der RadioButtons zu manipulieren (Hints anzeigen, verstecken,...) } { The property Controls lists all child controls of a Control.(Here a TRadioGroup) Controls is an array of all the child controls. The Controls property is convenient for referring to the children of a control by number rather than name. For example, Controls may be used to change properties of the Radiobuttons in a TRadioGroup (showing hints, hiding items,...) } {1. *******************************************************} // Deactivates/activates a specified item of a TRadioGroup // Deaktiviert/aktiviert in einer TRadioGroup ein bestimmtes Item procedure RGB_EnableItem(RadioGroup: TRadioGroup; ItemIndex: Byte; bEnabled: Boolean); begin RadioGroup.Controls[ItemIndex].Enabled := bEnabled; end; // Example: Deactivates the 2. Item (Index starts at 0) // Beispiel: 2. Item deaktivieren (Index beginnt bei 0) procedure TForm1.Button1Click(Sender: TObject); begin RGB_EnableItem(RadioGroup1, 1, False); end; {2. *******************************************************} // Hides/Shows a specified item of a TRadioGroup // Versteckt oder zeigt ein bestimmtes Item in einer TRadioGroup an. procedure RGB_ShowItem(RadioGroup: TRadioGroup; ItemIndex: Byte; bVisible: Boolean); begin RadioGroup.Controls[ItemIndex].Visible := bVisible; end; // Example: Hides the 2. Item (Index starts at 0) // Beispiel: 2. Item verstecken (Index beginnt bei 0) procedure TForm1.Button2Click(Sender: TObject); begin RGB_ShowItem(RadioGroup1, 1, False); end; {3. *******************************************************} // Show Hints for TRadioGroup items // Hints für die Items in der TRadioGroup anzeigen procedure TForm1.Button3Click(Sender: TObject); var i: Byte; begin for i := 0 to RadioGroup1.ControlCount - 1 do begin RadioGroup1.Controls[i].ShowHint := True; RadioGroup1.Controls[i].Hint := (Radiogroup1.Controls[i] as TRadiobutton).Caption; end; end; {4. *******************************************************} // Focus a specified Radiobutton in a TRadioGroup // Ein bestimmter Radiobutton einer TRadioGroup fokussieren procedure RGB_FocusItem(RadioGroup: TRadioGroup; ItemIndex: Byte); var RadiogroupClick: TNotifyEvent; begin if ItemIndex = 0 then begin RadioGroup.OnClick := nil; (RadioGroup.Controls[1] as TRadiobutton).SetFocus; RadioGroup.OnClick := RadiogroupClick; end; end; // Example: Focus the 2. Radiobutton // Beispiel: Den 2. Radiobutton fokussieren procedure TForm1.Button4Click(Sender: TObject); begin RGB_FocusItem(RadioGroup1, 1); end;