Ir al contenido


Foto

TNotifyEvent onclick


  • Por favor identifícate para responder
7 respuestas en este tema

#1 zealot2

zealot2

    Newbie

  • Miembros
  • Pip
  • 5 mensajes

Escrito 24 enero 2022 - 05:07

I  know that this foro is for delphi, but is the same for me.

I am using rad studio with c++. I had made a button from code with the following:

TButton *a = new TButton(this);
a->Parent = Form1;
a->Text = "dsssdsd";

Please I need asociate an onlick event for this button, I have tried for days, but nothing. Thanks.


  • 0

#2 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.446 mensajes
  • LocationMéxico

Escrito 24 enero 2022 - 07:34

I  know that this foro is for delphi, but is the same for me.

I am using rad studio with c++. I had made a button from code with the following:

TButton *a = new TButton(this);
a->Parent = Form1;
a->Text = "dsssdsd";

Please I need asociate an onlick event for this button, I have tried for days, but nothing. Thanks.

 

Hi zealot welcome to delphiaccess

 

I thing you need to add a new method and assign it to your button (like delphi)

 

Something like this:

 

On .h file


php
  1. void __fastcall TForm1::ClickEvent(TObject *Sender);

Assign Method


php
  1. a->OnClick = &ClickEvent;

Method


php
  1. void __fastcall TForm1::ClickEvent(TObject *Sender)
  2. {
  3. TButton *btn = dynamic_cast<TButton *>(Sender);
  4. // Do action here
  5. }

Regards


  • 1

#3 zealot2

zealot2

    Newbie

  • Miembros
  • Pip
  • 5 mensajes

Escrito 27 enero 2022 - 11:12

Hi zealot welcome to delphiaccess

 

I thing you need to add a new method and assign it to your button (like delphi)

 

Something like this:

 

On .h file


php
  1. void __fastcall TForm1::ClickEvent(TObject *Sender);

Assign Method


php
  1. a->OnClick = &ClickEvent;

Method


php
  1. void __fastcall TForm1::ClickEvent(TObject *Sender)
  2. {
  3. TButton *btn = dynamic_cast<TButton *>(Sender);
  4. // Do action here
  5. }

Regards

One millions of thanks egostar, you saved my life, I had proved it and works fine. Maybe could looks as simplicity code, but for my is very important.


  • 0

#4 zealot2

zealot2

    Newbie

  • Miembros
  • Pip
  • 5 mensajes

Escrito 27 enero 2022 - 02:39

Ohh God. I have another trouble, when I create many buttons, when I click someone the same codec occurs!!. How I can discriminate the codec for each button. Because the handler if the same!!. Thanks.


  • 0

#5 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.446 mensajes
  • LocationMéxico

Escrito 27 enero 2022 - 06:08

Ohh God. I have another trouble, when I create many buttons, when I click someone the same codec occurs!!. How I can discriminate the codec for each button. Because the handler if the same!!. Thanks.

 

No tengo idea, con Delphi es muy simple.

 

Saludos


  • 0

#6 zealot2

zealot2

    Newbie

  • Miembros
  • Pip
  • 5 mensajes

Escrito 28 enero 2022 - 07:18

haaa, que bien, hablas español colega que bueno. Si, lo que me mandaste me funciona bien muchas gracias, el problema es que si creo 5 botones dinamicos por ejemplo, todos ejecutan el mismo manejador de evento, no puedo discriminar entre un boton y otro, ese es el problema. No podria enviarme como lo haces en delphi, igual con el ejemplo de delphi me sirve. Gracias colega.


  • 0

#7 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.446 mensajes
  • LocationMéxico

Escrito 28 enero 2022 - 08:12

haaa, que bien, hablas español colega que bueno.


Hola, cuando vi tu perfil me entero que eres de Cuba, así que mejor hablamos en nuestro idioma :D
 

Si, lo que me mandaste me funciona bien muchas gracias, el problema es que si creo 5 botones dinamicos por ejemplo, todos ejecutan el mismo manejador de evento, no puedo discriminar entre un boton y otro, ese es el problema. No podria enviarme como lo haces en delphi, igual con el ejemplo de delphi me sirve. Gracias colega.


Bueno en Delphi solo asignamos el mismo evento a todos los botones y ejecuta el proceso que esté en dicho evento, quiero decir, no es necesario validar que botón fue presionado, me parece que falta algo de información para entender lo que necesitas.-

 

Saludos


 


  • 0

#8 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.107 mensajes
  • LocationMadrid - España

Escrito 28 enero 2022 - 10:48

Mediante el nombre del componente lo podemos diferenciar:
 

cpp
  1. void __fastcall TForm1::ClickEvent(TObject *Sender)
  2. {
  3. TButton *btn = dynamic_cast<TButton *>(Sender);
  4. if(btn)
  5. Label1->Caption = btn->Name;
  6. }

Saludos
  • 1




IP.Board spam blocked by CleanTalk.