Board index » cppbuilder » enhance my app

enhance my app


2005-02-01 12:19:00 AM
cppbuilder34
hi,
is it possible to catch all clicks to a TEdit in one(!) function in my app?
I'm nort in the mood to enhance every Edit in my application. Maybe with any
windows-message?
i want:
when one TEdit was selected i wanna color the background to yellow. if the
OnExit()-Function of the selected TEdit was released, i want to set the
color back to the default one. how do i do that?
Thank you!
 
 

Re:enhance my app

"Ron Eggler @ Work" < XXXX@XXXXX.COM >wrote:
Quote
hi,

is it possible to catch all clicks to a TEdit in one(!) function in my app?
I'm nort in the mood to enhance every Edit in my application. Maybe with any
windows-message?
i want:

when one TEdit was selected i wanna color the background to yellow. if the
OnExit()-Function of the selected TEdit was released, i want to set the
color back to the default one. how do i do that?
If I understand you correctly, you want to use the same even(s)
for several TEdits. That's what the Sender parameter is for:
//-------------------------------------------------------------
void __fastcall TForm1::EditEnter(TObject *Sender)
{
TEdit *pEdit = static_cast<TEdit*>( Sender );
pEdit->Color = clYellow;
}
//-------------------------------------------------------------
void __fastcall TForm1::EditExit(TObject *Sender)
{
TEdit *pEdit = static_cast<TEdit*>( Sender );
pEdit->Color = clWhite;
}
//-------------------------------------------------------------
Just use the Object Inspector to assign them by clicking on
the down arrow in the appropriate event listing.
~ JD
 

Re:enhance my app

In addition to what JD said, you can add a unique
'Tag' property to every TEdit:
Edit1->Tag = 1;
Edit2->Tag = 2;
Edit3->Tag = 3;
Edit4->Tag = 4;
// ...
(you can do this at design time also)
... and later in your shared function (EditEnter) easy find
out which control's event was triggered, to make some
special tasks:
/ untested /
void __fastcall TForm1::EditEnter(TObject *Sender)
{
int WhichWasTriggered = ( (TEdit*)Sender )->Tag;
switch ( WhichWasTriggered )
{
case 1: // The event was triggered because of Edit1 ...
// ...
}
--
Best regards,
Vladimir Stefanovic
"Ron Eggler @ Work" < XXXX@XXXXX.COM >wrote in message
Quote
hi,

is it possible to catch all clicks to a TEdit in one(!) function in my
app?
I'm nort in the mood to enhance every Edit in my application. Maybe with
any
windows-message?
i want:

when one TEdit was selected i wanna color the background to yellow. if the
OnExit()-Function of the selected TEdit was released, i want to set the
color back to the default one. how do i do that?

Thank you!


 

{smallsort}

Re:enhance my app

"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
Quote
In addition to what JD said, you can add a unique
'Tag' property to every TEdit:

Edit1->Tag = 1;
Edit2->Tag = 2;
Edit3->Tag = 3;
Edit4->Tag = 4;
// ...
(you can do this at design time also)

... and later in your shared function (EditEnter) easy find
out which control's event was triggered, to make some
special tasks:

/ untested /

void __fastcall TForm1::EditEnter(TObject *Sender)
{
int WhichWasTriggered = ( (TEdit*)Sender )->Tag;

switch ( WhichWasTriggered )
{
case 1: // The event was triggered because of Edit1 ...
// ...
}
You could do this, but it's not a very elegant solution IMHO. (A pig to
maintain)
I would do it like JD, but use dynamic_cast<>instead.
Simon.
 

Re:enhance my app

Quote
You could do this, but it's not a very elegant solution
IMHO. (A pig to maintain)
Yes, it could be the pig to maintain if there is a lot of code in
Quote
>case 1: // The event was triggered because of Edit1 ...
The code I presented is not intended to replace the JD's in
any way. It just shows how you can know what TEdit was
triggered althought you are in the shared function, and so take
some extra action like showing some message somewhere.
--
Best regards,
Vladimir Stefanovic
 

Re:enhance my app

"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
Quote
>You could do this, but it's not a very elegant solution
>IMHO. (A pig to maintain)

Yes, it could be the pig to maintain if there is a lot of code in

>>case 1: // The event was triggered because of Edit1 ...

The code I presented is not intended to replace the JD's in
any way. It just shows how you can know what TEdit was
triggered althought you are in the shared function, and so take
some extra action like showing some message somewhere.
If you need to know that you can compare Sender to the TEdit pointers.
I didn't mean to offend, but that method is not one to recommend. It
requires more code, and does not take advantage of the fact that Sender is a
pointer, it is harder to read and so harder to maintain. Can you at a glance
know which edit case 3 is? In this case you don't need to know, since the
same action is taking place on all edits.
Simon.
 

Re:enhance my app

JD wrote:
Quote
"Ron Eggler @ Work" < XXXX@XXXXX.COM >wrote:
>hi,
>
>is it possible to catch all clicks to a TEdit in one(!) function in
>my app? I'm nort in the mood to enhance every Edit in my
>application. Maybe with any windows-message?
>i want:
>
>when one TEdit was selected i wanna color the background to yellow.
>if the OnExit()-Function of the selected TEdit was released, i want
>to set the color back to the default one. how do i do that?

If I understand you correctly, you want to use the same even(s)
for several TEdits. That's what the Sender parameter is for:

//-------------------------------------------------------------
void __fastcall TForm1::EditEnter(TObject *Sender)
{
TEdit *pEdit = static_cast<TEdit*>( Sender );
pEdit->Color = clYellow;
}
//-------------------------------------------------------------
void __fastcall TForm1::EditExit(TObject *Sender)
{
TEdit *pEdit = static_cast<TEdit*>( Sender );
pEdit->Color = clWhite;
}
//-------------------------------------------------------------

Just use the Object Inspector to assign them by clicking on
the down arrow in the appropriate event listing.
Seems to be good but, i already got alot og code in every OnExit()-Function
of the TEdits which i need to execute.
so, is there a way to get the Senders name?
so i could call the function in EditExit() like:
void __fastcall TForm1::EditExit(TObject *Sender)
{
TEdit *pEdit = static_cast<TEdit*>( Sender );
pEdit->Color = clWhite;
pEdit->pEditExit(); // execute Edits original OnExit-Function.
}
 

Re:enhance my app

JD wrote:
Quote
"Ron Eggler @ Work" < XXXX@XXXXX.COM >wrote:
>hi,
>
>is it possible to catch all clicks to a TEdit in one(!) function in
>my app? I'm nort in the mood to enhance every Edit in my
>application. Maybe with any windows-message?
>i want:
>
>when one TEdit was selected i wanna color the background to yellow.
>if the OnExit()-Function of the selected TEdit was released, i want
>to set the color back to the default one. how do i do that?

If I understand you correctly, you want to use the same even(s)
for several TEdits. That's what the Sender parameter is for:

//-------------------------------------------------------------
void __fastcall TForm1::EditEnter(TObject *Sender)
{
TEdit *pEdit = static_cast<TEdit*>( Sender );
pEdit->Color = clYellow;
}
//-------------------------------------------------------------
void __fastcall TForm1::EditExit(TObject *Sender)
{
TEdit *pEdit = static_cast<TEdit*>( Sender );
pEdit->Color = clWhite;
}
//-------------------------------------------------------------

Just use the Object Inspector to assign them by clicking on
the down arrow in the appropriate event listing.
Seems to be good but, i already got alot og code in every OnExit()-Function
of the TEdits which i need to execute.
so, is there a way to get the Senders name?
so i could call the function in EditExit() like:
void __fastcall TForm1::EditExit(TObject *Sender)
{
TEdit *pEdit = static_cast<TEdit*>( Sender );
pEdit->Color = clWhite;
pEdit->pEditExit(); // execute Edits original OnExit-Function.
}
 

Re:enhance my app

Ron Eggler @ Work wrote:
Quote
JD wrote:
>"Ron Eggler @ Work" < XXXX@XXXXX.COM >wrote:
>>hi,
>>
>>is it possible to catch all clicks to a TEdit in one(!) function in
>>my app? I'm nort in the mood to enhance every Edit in my
>>application. Maybe with any windows-message?
>>i want:
>>
>>when one TEdit was selected i wanna color the background to yellow.
>>if the OnExit()-Function of the selected TEdit was released, i want
>>to set the color back to the default one. how do i do that?
>
>If I understand you correctly, you want to use the same even(s)
>for several TEdits. That's what the Sender parameter is for:
>
>//-------------------------------------------------------------
>void __fastcall TForm1::EditEnter(TObject *Sender)
>{
>TEdit *pEdit = static_cast<TEdit*>( Sender );
>pEdit->Color = clYellow;
>}
>//-------------------------------------------------------------
>void __fastcall TForm1::EditExit(TObject *Sender)
>{
>TEdit *pEdit = static_cast<TEdit*>( Sender );
>pEdit->Color = clWhite;
>}
>//-------------------------------------------------------------
>
>Just use the Object Inspector to assign them by clicking on
>the down arrow in the appropriate event listing.
Seems to be good but, i already got alot og code in every
OnExit()-Function of the TEdits which i need to execute.
so, is there a way to get the Senders name?
so i could call the function in EditExit() like:

void __fastcall TForm1::EditExit(TObject *Sender)
{
TEdit *pEdit = static_cast<TEdit*>( Sender );
pEdit->Color = clWhite;
pEdit->pEditExit(); // execute Edits original OnExit-Function.
}
Okay, I now did following:
void __fastcall TMain_Frm::EditEnter(TObject *Sender)
/* Funktion für alle Edits, um sie gelb zu färben bei aktivierung */
{
TEdit *pEdit=NULL;
for(int i = 0;i < this->ComponentCount;i++)
{
pEdit = dynamic_cast<TEdit*>(this->Components[i]);
if (pEdit != NULL) // Prüfen ob pEdit NULL ist
{
pEdit->Color= clWindow;
}
}
pEdit=NULL;
Application->ProcessMessages();
pEdit = dynamic_cast<TEdit*>(Sender);
if (pEdit != NULL) // Prüfen ob pEdit NULL ist
pEdit->Color = clYellow;
}
But i want to color it back to clWindow after the Exit-Function was executed
and not just, when annother Edit was selected.
 

Re:enhance my app

"Simon D" < XXXX@XXXXX.COM >wrote:
Quote

[...] I would do it like JD, but use dynamic_cast<>instead.
In this case, dynamic_cast is the wrong approach because the
only thing that it gives you is additional overhead. Consider
what the coding would be if you used it:
TEdit *pEdit = dynamic_cast<Tedit*>( Sender );
if( pEdit ) pEdit->Color = clYellow;
else throw Exception( "The programmer screwed-up and " +
"assigned this event to a control " +
"that isn't a TEdit");
dynamic_cast should be used when you're not sure of the
control's type. Here, you should be sure and in any case, it
should be caught during development and the extra overhead
associated with dynamic_cast should not be in the application.
~ JD
 

Re:enhance my app

"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote:
Quote

[...] int WhichWasTriggered = ( (TEdit*)Sender )->Tag;
In this case, it makes little difference but you should get
away from using old c-style casting. Let the compiler work for
you.
~ JD
 

Re:enhance my app

"Ron Eggler @ Work" < XXXX@XXXXX.COM >wrote:
Quote

Please trim your posts. Help keep the server less cluttered.
Quote
[...] But i want to color it back to clWindow after the Exit-
Function was executed and not just, when annother Edit was
selected.
That is exactly what the code I posted does. Did you assign the
events to all of the TEdits?
~ JD
 

Re:enhance my app

JD wrote:
Quote
"Ron Eggler @ Work" < XXXX@XXXXX.COM >wrote:
>

Please trim your posts. Help keep the server less cluttered.

>[...] But i want to color it back to clWindow after the Exit-
>Function was executed and not just, when annother Edit was
>selected.

That is exactly what the code I posted does. Did you assign the
events to all of the TEdits?
that's correct, but u forgot that i already have alot of code in my OnExit
functions from the TEdits.
Quote

~ JD
 

Re:enhance my app

"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"Simon D" < XXXX@XXXXX.COM >wrote:
>
>[...] I would do it like JD, but use dynamic_cast<>instead.

In this case, dynamic_cast is the wrong approach because the
only thing that it gives you is additional overhead. Consider
what the coding would be if you used it:

TEdit *pEdit = dynamic_cast<Tedit*>( Sender );
if( pEdit ) pEdit->Color = clYellow;
else throw Exception( "The programmer screwed-up and " +
"assigned this event to a control " +
"that isn't a TEdit");
Your comment explains exactly why I would use it. Belt and braces...
Simon.
 

Re:enhance my app

"Simon D" < XXXX@XXXXX.COM >wrote:
Quote

Your comment explains exactly why I would use it. Belt and braces...
That makes no sense. The *only* benifit would be during
developement and all it would do is replace one type of error
with an other. The difference being extra overhead in the
final product that has no purpose. It's just extra overhead
that needs to be removed.
~ JD