Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Privileged instruction (https://www.clubdelphi.com/foros/showthread.php?t=65424)

LiAnTe- 14-12-2009 00:15:46

Privileged instruction
 
Hola a Tod@s,

estoy creando botones en tiempo de ejecucion y le quiero asignar un OnClick a cada boton pero despues de crear este codigo....

Código Delphi [-]
procedure TGesVentasBar.FormCreate(Sender: TObject);
var vPersonalNombre : String;
    vTop            : Integer;
    vInicio         : Integer;
    vPestanya       : TWinControl;
    vBotonOnClick   : TNotifyEvent;

begin
  ListaImagenes := TStringlist.Create;

  Boton := TButton.create(self);
  boton.Caption := 'Hola';
  boton.Height := 120;
  boton.Left := 20;
  boton.Width := 130;
  boton.Enabled := True;
  Boton.visible := True;
  boton.Show;

  vTop := 1;
  vPestanya := Personal;
  vInicio := 1;

  BDades.TPersonal.Active := False;
  BDades.TPersonal.SelectSQL.Text := 'Select * from Personal where tienda = ' + '''' + BDades.TConfigTIENDA.Text + '''';
  BDades.TPersonal.Open;
  BDades.TPersonal.Active := True;
  BDades.TPersonal.First;

    While BDades.TPersonal.Eof = False do
     Begin
      vPersonalNombre := BDades.TPersonal.FieldByName('NOMBRE').AsString;
      vPersonalCodigo := BDades.TPersonal.FieldByName('CODIGO').AsInteger;

      Boton := TButton.create(self);
      boton.Parent  := vPestanya;
      boton.Caption := vPersonalNombre;
      boton.Height  := 69;
      boton.Width   := 120;
      boton.Left    := vInicio;     // Inicio
      boton.Top     := vTop;     // Altura
      boton.Enabled := True;
      Boton.visible := True;
      Boton.Tag     := vPersonalCodigo;
      Boton.OnClick := vBotonOnClick;
//      ShowMessage('Se ha pulsado el botón :' + TButton(Sender).Name);


      boton.Show;
      BDades.TPersonal.Next;
      vTop := vTop + 70;

      if vTop > 420 Then
      Begin
        vInicio := 1;
        vTop := 1;
        vPestanya := Personal2;
      end;
    end;

end;

      procedure TGesVentasBar.vBotonOnClick(Sender: TObject);
      Begin
        ShowMessage(inttostr(vPersonalCodigo));
//        Vendedor.text := vPersonalCodigo;
        Case TButton(Sender).Tag of
          1 : Showmessage(TButton(Sender).Name);
          2 : Showmessage(TButton(Sender).Name);
        end;
      end;

cuando pulso en el boton me pone Privileged instruction alguien me puede ayudar?

saludos.

Neftali [Germán.Estévez] 14-12-2009 12:49:52

Por favor, utiliza etiquetas cuandos escribas código delphi, de otra forma es bastante incómodo leerlo.

Neftali [Germán.Estévez] 14-12-2009 12:52:20

¿Has ejecutado paso a paso?
¿Sabes la línea dónde te está saltando el error?

Lepe 14-12-2009 15:15:06

A mí la variable vPersonalCodigo me tiene mosqueado ;). No sé donde se define.

- Si está en la zona interface de TGesVentasBar no debería dar problemas.
- Si está declarada en otra ventana o unidad... pues puede ser ese el fallo.

Mi sugerencia es quites la primera linea del evento: vBotonOnClick (el primer showMessage), así no debería dar problemas.

camariere 14-12-2009 17:14:37

Yo creo que el problema está en esta variable....

Código Delphi [-]
    vBotonOnClick   : TNotifyEvent;

¿No debería estar declarado como un procedimiento?

Código Delphi [-]

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure vBotonOnClick(Sender: TObject); //Aquí se declara el evento
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Boton: Tbutton;

implementation

{$R *.DFM}

procedure TForm1.vBotonOnClick(Sender: TObject);
var
  Texto: string;
begin
  texto := (Sender as TButton).caption;
  ShowMessage('Botón <'+texto+'> presionado');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Boton := TButton.create(Form1);
  Boton.Parent := Form1;
  Boton.Caption := 'Hola';
  Boton.Height := 120;
  Boton.Left := 20;
  Boton.Width := 130;
  Boton.Enabled := True;
  Boton.visible := True;
  Boton.OnClick := vBotonOnClick; //se asigna el evento
end;


La franja horaria es GMT +2. Ahora son las 08:01:33.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi