 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Henk van Winkoop Guest
|
Posted: Tue Apr 18, 2006 1:05 pm Post subject: OnExit question |
|
|
Hello,
I use a TComboBox on a TPanel.
I want to check the user input in the TComboBox for illegal values.
If an illegal value is found no further action may be executed by the user.
I use the TComboBox->OnExit event to check the user input.
If I place an illegal value in the TComboBox and then click on some
application TButton, then first that TButton->OnClick event is
executed and then the TComboBox->OnExit event is executed.
I would like to have the TButton return without doing something
when the TComboBox->OnExit detects an error. So TComboBox->OnExit
Setting a flag that can be checked by TButton.
I found a solution by using a dummy TEdit that gets the focus if
a TButton is pressed. So focus changes to TEdit which generates
an TComboBox->OnExit event, which sets an error flag which
is then checked by TButton.
To me this seems very unprofessional programming.
How should I solve this problem?
Regards,
Henk |
|
| Back to top |
|
 |
Clayton Arends Guest
|
Posted: Tue Apr 18, 2006 4:03 pm Post subject: Re: OnExit question |
|
|
From my experience OnExit is handled first. Try this:
// Create new application, add a Button and an Edit to
// the form. Add an OnExit handler for the Edit and
// and OnClick handler for the button
void __fastcall TForm1::Edit1Exit(TObject *Sender)
{
ShowMessage("Exit");
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ShowMessage("Click");
}
- Clayton |
|
| Back to top |
|
 |
Henk van Winkoop Guest
|
Posted: Tue Apr 18, 2006 8:03 pm Post subject: Re: OnExit question |
|
|
Yes, in your case you are right, but,
I use a dynamically created TComboBox on a dynamically created TPanel.
And my button is a TToolbarButton.
Henk
"Clayton Arends" <nospam_claytonarends (AT) hotmail (DOT) com> schreef in bericht
news:4445045d (AT) newsgroups (DOT) borland.com...
| Quote: | From my experience OnExit is handled first. Try this:
// Create new application, add a Button and an Edit to
// the form. Add an OnExit handler for the Edit and
// and OnClick handler for the button
void __fastcall TForm1::Edit1Exit(TObject *Sender)
{
ShowMessage("Exit");
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ShowMessage("Click");
}
- Clayton
|
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Tue Apr 18, 2006 9:03 pm Post subject: Re: OnExit question |
|
|
"Henk van Winkoop" <h.van.winkoop (AT) wxs (DOT) nl> wrote:
| Quote: |
Yes, in your case you are right, but, I use [...] a TToolbarButton.
|
That makes a huge difference. It's difficult for other to help
when they don't have all of the facts and are unable to
reproduce your problem.
For any OnExit to fire, focus must change. A TButton decends
from TWinControl and as such can be focused. A TToolButton
does not and can not be focused so when it's clicked, *any*
OnExit will not be called.
This will work for you:
protected: // User declarations
virtual void __fastcall WndProc( TMessage &Message );
//-------------------------------------------------------------
void __fastcall TForm1::ToolButton1Click(TObject *Sender)
{
if( ActiveControl == ComboBox1 && InvalidComboBox1Entry() ) return;
// button click code goes here
}
//-------------------------------------------------------------
void __fastcall TForm1::ComboBox1Exit(TObject *Sender)
{
if( InvalidComboBox1Entry() ) ::PostMessage( Handle, WM_USER + 100, 0, 0 );
}
//-------------------------------------------------------------
bool __fastcall TForm1::InvalidComboBox1Entry()
{
if( the text is valid ) return true;
return false;
}
//-------------------------------------------------------------
void __fastcall TForm1::WndProc( TMessage &Message )
{
if( Message.Msg == WM_USER + 100 )
{
ComboBox1->SetFocus();
}
TForm::WndProc( Message );
}
//-------------------------------------------------------------
~ JD |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|