Search code examples
c++c++builderborland-c++

Basic Enter key functionality in C++Builder


I am currently porting an old Borland C++Builder 5 project to C++Builder 10.3.

I have successfully ported all the project files, and it compiles and runs as intended, however there is an issue with the Enter key in some of the Forms.

The old project would always execute the same functionality as double clicking an item in the Form without the use of explicit code.

In the new project, this is not working. Pressing the Enter key on a selected object does nothing.

Is there some property in C++Builder 10.3 that needs to be set for this? Or, is it mandatory to write the explicit code in the Form's OnKeyPress event?


Solution

  • Using C++Builder 10.4, I added a VCL ListView to a form with two items. I set up the ListView onKeyPress event handler. Then when I select one or the other items in the ListView and hit the enter key, I get the caption for the ListItem that was selected.

    void __fastcall TForm1::ListView1KeyPress(TObject *Sender, System::WideChar &Key)
    {
        if(ListView1->Selected)
        {
           Label1->Caption =
               ListView1->Items->Item[ListView1->Selected->Index]->Caption;
        }
    }
    

    Does this match code you have been using with older version of C++BUilder?