CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Join Date
    May 2010
    Posts
    8

    Smile 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;
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Press Enter Twice

    Quote Originally Posted by alone882 View Post
    My Code:
    void __fastcall TForm1::ListBox1KeyPress(TObject *Sender, char &Key)
    {
    ...
    }
    What is TObject *Sender?
    Victor Nijegorodov

  3. #3
    Join Date
    May 2010
    Posts
    8

    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

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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?
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Press Enter Twice

    Quote Originally Posted by alone882 View Post
    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

  6. #6
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Press Enter Twice

    Quote Originally Posted by alone882 View Post
    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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  7. #7
    Join Date
    May 2010
    Posts
    8

    Re: Press Enter Twice

    But how about - CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming ?

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Press Enter Twice

    Quote Originally Posted by alone882 View Post
    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

  9. #9
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    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.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  10. #10
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    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

  11. #11
    Join Date
    Aug 2008
    Posts
    902

    Re: Press Enter Twice

    Quote Originally Posted by VictorN View Post
    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.

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Press Enter Twice

    Quote Originally Posted by Chris_F View Post
    Must be Borland's library.
    No, it might be and it might be not.
    And the fact is there is not.

    Quote Originally Posted by Chris_F View Post
    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

  13. #13
    Join Date
    Aug 2008
    Posts
    902

    Re: Press Enter Twice

    Quote Originally Posted by VictorN View Post
    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.

    Quote Originally Posted by VictorN View Post
    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.

  14. #14
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Press Enter Twice

    Quote Originally Posted by Chris_F View Post
    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?
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  15. #15
    Join Date
    May 2010
    Posts
    8

    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 .. ?

Page 1 of 2 12 LastLast

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
  •  





Click Here to Expand Forum to Full Width

Featured