Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 14-12-2009
LiAnTe- LiAnTe- is offline
Miembro
 
Registrado: oct 2007
Posts: 47
Poder: 0
LiAnTe- Va por buen camino
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.

Última edición por Neftali [Germán.Estévez] fecha: 14-12-2009 a las 12:50:42. Razón: Añadidas etiquetas TAG's
Responder Con Cita
  #2  
Antiguo 14-12-2009
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.275
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Por favor, utiliza etiquetas cuandos escribas código delphi, de otra forma es bastante incómodo leerlo.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
  #3  
Antiguo 14-12-2009
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.275
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
¿Has ejecutado paso a paso?
¿Sabes la línea dónde te está saltando el error?
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
  #4  
Antiguo 14-12-2009
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Poder: 28
Lepe Va por buen camino
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.
__________________
Si usted entendió mi comentario, contácteme y gustosamente,
se lo volveré a explicar hasta que no lo entienda, Gracias.
Responder Con Cita
  #5  
Antiguo 14-12-2009
camariere camariere is offline
Miembro
 
Registrado: abr 2008
Posts: 37
Poder: 0
camariere Va por buen camino
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;
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Privileged Instruction ajgomezlopez Lazarus, FreePascal, Kylix, etc. 4 22-03-2009 14:30:27
Privileged instruction luis1980 C++ Builder 3 29-08-2008 08:02:13
QReport. Error "Privileged instruction" adebonis Impresión 0 11-12-2004 07:34:42
Rave -- Privileged Instruction altp Impresión 0 19-07-2004 18:33:12
privileged instruction Juan C Robles Varios 1 31-10-2003 03:14:45


La franja horaria es GMT +2. Ahora son las 16:28:47.


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
Copyright 1996-2007 Club Delphi