whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

50 Visitors Online


 
...access the controls of a TRadioGroup?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (13):  
     




{
  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;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners