BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

OnExit question

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Henk van Winkoop
Guest





PostPosted: Tue Apr 18, 2006 1:05 pm    Post subject: OnExit question Reply with quote



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





PostPosted: Tue Apr 18, 2006 4:03 pm    Post subject: Re: OnExit question Reply with 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
Henk van Winkoop
Guest





PostPosted: Tue Apr 18, 2006 8:03 pm    Post subject: Re: OnExit question Reply with quote



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





PostPosted: Tue Apr 18, 2006 9:03 pm    Post subject: Re: OnExit question Reply with quote

"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.