Ver Mensaje Individual
  #1  
Antiguo 15-09-2015
gustavosv gustavosv is offline
Miembro
 
Registrado: mar 2008
Posts: 51
Reputación: 17
gustavosv Va por buen camino
Enlazando un evento OnClick a mi componente

Hola, tengo la siguiente definición de una clase que implementa un 'componente' y no sé que debo hacer para enlazar el OnClick del botón:

Código Delphi [-]
  TPruebaOnClic = class(TControl)
  private
    FRectang: TRectangle;
    FBoton: TButton;
    FOnClic: TNotifyEvent;
  public
    constructor Create(AOwner: TFmxObject);

    property OnClicBoton: TNotifyEvent read FOnClic write FOnClic;
  end;

constructor TPruebaOnClic.Create(AOwner: TFmxObject);
begin
  FRectang := TRectangle.Create(AOwner);
  with FRectang do
  begin
    Parent := AOwner;
    Align := TAlignLayout.Client;
    Opacity := 0.8;
  end;

  FBoton := TButton.Create(AOwner);
  with FBoton do
  begin
    Parent := FRectang;
    Align := TAlignLayout.Center;
    OnClick := FOnClic;
    Visible := True;
  end;
end;

Ahora desde la aplicación que usa el 'componente' ...

Código Delphi [-]
procedure TForm1.FormCreate(Sender: TObject);
begin
  Boton := TPruebaOnClic.Create(Panel1);
  Boton.OnClicBoton := OnClicOpc1;
end;

procedure TForm1.OnClicOpc1(Sender: TObject);
begin
  showmessage('estamos en grabar trabajo');
end;

Al ejecutarla, se muestra el rectángulo con el botón, pero no se ejecuta el evento al hacer clic sobre el botón.

No se hace de esa manera ...?

Gracias.

GustavoSV
Responder Con Cita