Ver Mensaje Individual
  #13  
Antiguo 13-04-2012
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Reputación: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
Cita:
Empezado por Delphius Ver Mensaje
Existe un control que justamente simplifica mucho el trabajo sobre un "grupo" o lista de CheckBoxs... el componente se llama TCheckListBox [...]
Este componente es simplemente un TListbox con checkboxs dentro, con lo que basta con recorrer la propiedad vectorial y los items para acceder a cada checkbox.
Buena opción, pero con la limitante de que no puedes acomodar tus checkbox a tu gusto. Sin embargo, pensando en esta opción, se me ocurre que puede crearse un componente sencillo derivado de TGroupBox:

Código Delphi [-]
unit CheckGroup;

interface

uses Classes, StdCtrls, Contnrs;

type
  TCheckGroup = class(TGroupBox)
  private
    FItems: TObjectList;

    function GetItem(Index: Integer): TCheckBox;
    function GetItemCount: Integer;

  protected
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
    
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    property Items[Index: Integer]: TCheckBox read GetItem;
    property ItemCount: Integer read GetItemCount;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('ClubDelphi', [TCheckGroup]);
end;

{ TCheckGroup }

constructor TCheckGroup.Create(AOwner: TComponent);
begin
  inherited;
  FItems := TObjectList.Create(false);
end;

destructor TCheckGroup.Destroy;
begin
  FItems.Free;
  inherited;
end;

function TCheckGroup.GetItem(Index: Integer): TCheckBox;
begin
  Result := TCheckBox(FItems[Index]);
end;

function TCheckGroup.GetItemCount: Integer;
begin
  Result := FItems.Count;
end;

procedure TCheckGroup.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited;

  case Operation of
    opInsert:
      if AComponent is TCheckBox then
        FItems.Add(AComponent);

    opRemove:
      if AComponent is TCheckBox then
        FItems.Remove(AComponent);
  end;
end;

end.

Con este componente tendrías en Items el arreglo de CheckBox real. En un TCheckListBox lo que tienes son propiedades vectoriales para cada propiedad de un CheckBox: ItemEnabled, Checked, State. La ventaja sería, además de colocar los controles como gustes, que puedes insertar otro tipo de controles y la propiedad vectorial reflejaría sólo los checkbox.

// Saludos
Responder Con Cita