-
January 2nd, 2011, 02:25 PM
#1
Press Enter Twice
Hi, I`m new here and, of course, have a small problem.
I need to create a program with VC++ 6 Builder where:
Press ENTER once - open picture,
Press ENTER Twice - start a music.
I can`t figure out how to check if user press ENTER twice, can anybody help me?
My Code:
void __fastcall TForm1::ListBox1KeyPress(TObject *Sender, char &Key)
{
switch( Key )
{
case 'VK_RETURN':
{ atidarytpav(); }
break;
}
-
January 2nd, 2011, 03:14 PM
#2
Re: Press Enter Twice
Originally Posted by alone882
My Code:
void __fastcall TForm1::ListBox1KeyPress(TObject *Sender, char &Key)
{
...
}
What is TObject *Sender?
Victor Nijegorodov
-
January 2nd, 2011, 03:20 PM
#3
Re: Press Enter Twice
The :ListBox1KeyPress method takes a pointer to a TObject called Sender. Mostly, every event handler, in c++, will have at least a Sender parameter. When the button is clicked, the event handler (:ListBox1KeyPress) for the KeyPress event is called.
The parameter "Sender" references the control that was used to call the method. If you press on the ListBox1 control, causing the ListBox1KeyPress method to be called, a reference or pointer to the ListBox1 object is passed to ListBox1KeyPress in the parameter called Sender
-
January 2nd, 2011, 03:24 PM
#4
Re: Press Enter Twice
Here is a (Microsoft) Visual C++ forum and not a (Borland) C++ Builder one.
However, is any problem for you to keep a member variable in TForm1 class which keeps the number of Enter keystrokes?
-
January 2nd, 2011, 03:28 PM
#5
Re: Press Enter Twice
Originally Posted by alone882
The :ListBox1KeyPress method takes a pointer to a TObject called Sender. Mostly, every event handler, in c++, will have at least a Sender parameter. When the button is clicked, the event handler (:ListBox1KeyPress) for the KeyPress event is called.
The parameter "Sender" references the control that was used to call the method. If you press on the ListBox1 control, causing the ListBox1KeyPress method to be called, a reference or pointer to the ListBox1 object is passed to ListBox1KeyPress in the parameter called Sender
Sorry, but my MSDN doesn't mention anything looking like TObject. And I don't need anything but TObject description in order to help you.
Victor Nijegorodov
-
January 2nd, 2011, 03:43 PM
#6
Re: Press Enter Twice
Originally Posted by alone882
every event handler, in c++, will have at least a Sender parameter.
Probably in a library shipped with Borland C++ Builder. Not "in c++" in general.
As I already said, you have not posted in the right forum.
-
January 2nd, 2011, 03:53 PM
#7
Re: Press Enter Twice
But how about - CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming ?
-
January 2nd, 2011, 04:01 PM
#8
Re: Press Enter Twice
Originally Posted by alone882
But how about - CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming ?
As stated it is:
Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.
Victor Nijegorodov
-
January 2nd, 2011, 04:45 PM
#9
Re: Press Enter Twice
alone882 these days there are quite few that use Borland C++ Builder. Version 6 is also very old/outdated so I guess that will make it even harder to get help.
I would try http://embarcadero.com/ and see if they have a link to some C++ Builder community.
-
January 3rd, 2011, 06:33 AM
#10
Re: Press Enter Twice
I can`t figure out how to check if user press ENTER twice, can anybody help me?
This implies some waiting should be done after first Enter for a short period to see if the second Enter comes (similar to mouse double click logic).
The form starts timer (say, 200-500ms) on first Enter and set some flag which should be reset when the second Enter arrives before the timer elapses. In case another Enter arrives when the flag is set, it means "double Enter" event to fire (resetting the flag as well). In case timer elapses with the flag set (which means there was no second Enter within the period), it resets the flag and fires "single Enter" event.
Best regards,
Igor
-
January 3rd, 2011, 06:41 AM
#11
Re: Press Enter Twice
Originally Posted by VictorN
Sorry, but my MSDN doesn't mention anything looking like TObject. And I don't need anything but TObject description in order to help you.
Must be Borland's library. In .NET there is a base class called Object, from which everything derives. WinForms' implementation of event handler callbacks take two parameters, Object Sender and an event argument class. This looks to use the same concept. So a TObject pointer is just a base pointer to some control that is responsible for raising the event.
-
January 3rd, 2011, 06:50 AM
#12
Re: Press Enter Twice
Originally Posted by Chris_F
Must be Borland's library.
No, it might be and it might be not.
And the fact is there is not.
Originally Posted by Chris_F
In .NET there is a base class called Object, from which everything derives. WinForms' implementation of event handler callbacks take two parameters, ...
Perhaps you should then ask it in the .NET forum?
Victor Nijegorodov
-
January 3rd, 2011, 06:54 AM
#13
Re: Press Enter Twice
Originally Posted by VictorN
Perhaps you should then ask it in the .NET forum?
I am not the originator of this thread, so I have no need to ask this question anywhere. Even then, I merely stated that the code he posted is similar to .NET in design. However TObject is most assuredly not a part of the .NET library, so asking this question there would be extremely foolish.
Originally Posted by VictorN
No, it might be and it might be not.
And the fact is there is not.
Admittedly I haven't done much research, but everything I've seen while searching seems to tie the TObject class to Borland/C++ and Delphi. Do I have any proof that this is what alone882 is using? No. But I'd be willing to make a wager that it is.
Lastly, I fail to see how this is even relevant. His problem isn't with his use of the GUI library, it's a simple problem that could arise in MFC, .NET, Delphi, or what have you. He simply needs to create a variable to store whether or not the button has been clicked previously to see which action should be taken.
Last edited by Chris_F; January 3rd, 2011 at 07:07 AM.
-
January 3rd, 2011, 07:53 AM
#14
Re: Press Enter Twice
Originally Posted by Chris_F
ILastly, I fail to see how this is even relevant. His problem isn't with his use of the GUI library, it's a simple problem that could arise in MFC, .NET, Delphi, or what have you. He simply needs to create a variable to store whether or not the button has been clicked previously to see which action should be taken.
Well then, a quick answer?
-
January 3rd, 2011, 04:04 PM
#15
Re: Press Enter Twice
Ok I have this script
Code:
int pressCount = 0;
void __fastcall TForm1::ListBox1KeyPress(TObject *Sender, char &Key)
{
switch( Key )
{
case 'VK_RETURN':
{
atidarytpav();
pressCount = ++pressCount % 2 }
if (count != 0)
{
//first time
}
else
{
//second time
pressCount = 0;
}
break;
}
but now say
Code:
Undefined symbol 'count'
Do I need some library or what .. ?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|