Board index » cppbuilder » How to assign a function to an event Handler?

How to assign a function to an event Handler?

I need to make a function that can be used by several TImage objects.
I'm creating at runtime these TImage objects, that must be visible in the
main form, so how can I access, use, their OnClick events using a predefined
function, that is equal to all TImage objects.

Best regards,

espec...@esoterica.pt

 

Re:How to assign a function to an event Handler?


Hi Espectro.

Perhaps i don't understand your question but
i think it's so easy.

Assign all the TImages OnClick events to the same function.
_____________________________________________________________

Espectro escribi en mensaje <7dc3v2$ok...@forums.borland.com>...

Quote
>I need to make a function that can be used by several TImage objects.
>I'm creating at runtime these TImage objects, that must be visible in the
>main form, so how can I access, use, their OnClick events using a
predefined
>function, that is equal to all TImage objects.

>Best regards,

>espec...@esoterica.pt

Re:How to assign a function to an event Handler?


How do I do that if I create those TImages at runtime?
Using what command?

Image1->OnClick .......... What????
I need to assign the function to the OnClick event, not in the Object
Inspector.

Thanks,

My UIN is 3623803, please talk to me!!!!!

Jose Luis Fari?as Costas wrote in message
<7dc4tf$ok...@forums.borland.com>...

Quote
>Hi Espectro.

>Perhaps i don't understand your question but
>i think it's so easy.

>Assign all the TImages OnClick events to the same function.
>_____________________________________________________________

>Espectro escribi en mensaje <7dc3v2$ok...@forums.borland.com>...
>>I need to make a function that can be used by several TImage objects.
>>I'm creating at runtime these TImage objects, that must be visible in the
>>main form, so how can I access, use, their OnClick events using a
>predefined
>>function, that is equal to all TImage objects.

>>Best regards,

>>espec...@esoterica.pt

Re:How to assign a function to an event Handler?


Try to write:

    Image1->OnClick = FunctionName;

_____________________________________________________
Espectro escribi en mensaje <7dc58p$oj...@forums.borland.com>...

Quote
>How do I do that if I create those TImages at runtime?
>Using what command?

>Image1->OnClick .......... What????
>I need to assign the function to the OnClick event, not in the Object
>Inspector.

Re:How to assign a function to an event Handler?


I'm having some kind of pointer problems, that I'm going to try solve.
I thought that way it couldn't work, but I'm an open minded man.

Thanks, once again,

espec...@esoterica.pt

Jose Luis Fari?as Costas wrote in message
<7dc5nd$ok...@forums.borland.com>...

Quote
>Try to write:

>    Image1->OnClick = FunctionName;

>_____________________________________________________
>Espectro escribi en mensaje <7dc58p$oj...@forums.borland.com>...
>>How do I do that if I create those TImages at runtime?
>>Using what command?

>>Image1->OnClick .......... What????
>>I need to assign the function to the OnClick event, not in the Object
>>Inspector.

Re:How to assign a function to an event Handler?


Your advice seems not to work, Jose.

excerpt of my code:

void __fastcall TForm1::Novojogo1Click(TObject *Sender)
{
 Carta* blocodestino[3];   // bloco de destino final
 Carta* blocotmp[3];         // bloco temporrio
 Carta* blocojogo[8];        // bloco de jogo
 Baralho* baralho=new Baralho;

 baralho->Baralhar();     // baralhar as cartas
 *baralhofixo=*baralho; // duplicacao do conteudo do baralho j baralhado
para o baralho fixo
                                        // que serve para, se mais tarde
quisermos recome?ar o jogo
                                        // carregarmos o baralho fixo;
 baralho->Cartas[1]->Imagem->OnClick=ImagemClick(this);

Quote
}                                                                 //  ^-----

The cursor stops here  \\

void __fastcall TForm1::ImagemClick (TObject *Sender)      // No return type
works
{
 Carta* blocodestino[3];             // Testing variable, not final

Quote
};

it gives the following error:

(C++ Error) ... Not an allowed type

Help really needed, to solve this problem or give another idea.

Thanks

espec...@esoterica.pt

Jose Luis Fari?as Costas wrote in message
<7dc5nd$ok...@forums.borland.com>...

Quote
>Try to write:

>    Image1->OnClick = FunctionName;

>_____________________________________________________
>Espectro escribi en mensaje <7dc58p$oj...@forums.borland.com>...
>>How do I do that if I create those TImages at runtime?
>>Using what command?

>>Image1->OnClick .......... What????
>>I need to assign the function to the OnClick event, not in the Object
>>Inspector.

Re:How to assign a function to an event Handler?


Hi,
Take a look at
www.bcbdev.com      faq's: Assign event handlers at runtime

Best Regards
Hakki Dogusan

Quote
Espectro wrote in message <7dcavq$p...@forums.borland.com>...
>Your advice seems not to work, Jose.

Re:How to assign a function to an event Handler?


Thanks, Hakki this should help,
Thanks, Jose for your help to.

espec...@esoterica.pt

Quote
Hakki Dogusan wrote in message <7dciau$pi...@forums.borland.com>...
>Hi,
>Take a look at
>www.bcbdev.com      faq's: Assign event handlers at runtime

>Best Regards
>Hakki Dogusan

>Espectro wrote in message <7dcavq$p...@forums.borland.com>...
>>Your advice seems not to work, Jose.

Re:How to assign a function to an event Handler?


Yoy must write the FunctionName without brackets, like that:

baralho->Cartas[1]->Imagem->OnClick=ImagemClick;
_____________________________________________

Espectro escribi en mensaje <7dcavq$p...@forums.borland.com>...

Quote
>Your advice seems not to work, Jose.

>excerpt of my code:

> baralho->Cartas[1]->Imagem->OnClick=ImagemClick(this);

Other Threads