Ver Mensaje Individual
  #16  
Antiguo 31-01-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola subzero.

Probá de este modo:
Código Delphi [-]
...
type
  TForm1 = class(TForm)
  ...
  procedure TForm1.FormShow(Sender: TObject);
  private
    procedure EventoClick(Sender: TObject);
    procedure CrearBotones(ACol: Integer);
    procedure BorrarColumna(ACol: Integer);
  public
  end;
...

implementation


procedure TForm1.EventoClick(Sender: TObject);
begin
  ShowMessage('Click en botón de StringGrid');
end;

(* Crear botones *)
procedure TForm1.CrearBotones(ACol: Integer);
var
  i: Integer;
  Btn: TButton;
begin
  for i := StringGrid1.FixedRows to StringGrid1.RowCount -1 do
  begin
    Btn           := TButton.Create(nil);
    Btn.Caption   := 'Quitar';
    Btn.Width     := 87;
    Btn.Name      := 'Button' + IntToStr(i);
    Btn.BoundsRect:= StringGrid1.CellRect(ACol, i);
    Btn.ControlStyle := [csClickEvents];
    Btn.OnClick   := EventoClick;
    Btn.Parent    := StringGrid1;
    StringGrid1.Objects[ACol,i] := Btn;
  end;
end;

(* Borrar columna *)
type
  TStringGridExt = class(Grids.TStringGrid);

procedure TForm1.BorrarColumna(ACol: Integer);
begin
  TStringGridExt(StringGrid1).DeleteColumn(ACol);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  ...
  CrearBotones(StringGrid1.RowCount-1);
end;

...
(* Liberar botones *)
procedure TForm1.FormDestroy(Sender: TObject);
var
  i: Integer;
begin
 for i := StringGrid1.FixedRows to StringGrid1.RowCount-1 do
    StringGrid1.Objects[StringGrid1.RowCount-1, i].Free;
end;

Llamada de ejemplo:
Código Delphi [-]
procedure TForm1.btBorrarClick(Sender: TObject);
begin
  BorrarColumna(1);
end;

Un saludo.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 31-01-2012 a las 23:09:41. Razón: Agregar comentario
Responder Con Cita