Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edittext ant OnKeyDown

Status
Not open for further replies.

vaidotas

Technical User
Sep 1, 2010
1
LT
Hello everybody.
I'm making software to control microchip via USB. The problem starts when I want to make OPTIONS window, there you can change keyboard buttons. First, i made a simple OnKeyDown program if ( Key == 'R') led_on(); everything works allright.
But if I take letter from EditText, it won't work, for example, if I write "T" in Edit screen, when it doesn't matter which key I press, the KeyDown funkcion does work.
So, my question, how to move the letter from EditText to Key, becouse one is ansistring, and other unsigned int i think.
Thank you.
 
So, my question, how to move the letter from EditText to Key, becouse one is ansistring, and other unsigned int i think.
You don't need to move a character from AnsiString to key. You can do a comparison directly. The following example will show you how but I will do it step by step with comments. You should be able to see how to shorten it.

First, I am assuming that the Edit box is named MyEdit. Second, I moved the code from OnKeyPress to OnExit but you can use the code almost anyplace.
Code:
void __fastcall TForm1::MyEditExit(TObject *Sender)
{
    // The following puts the text from MyEdit into an AnsiString as uppercase
    AnsiString MyEditStr = (MyEdit->Text).UpperCase(); 
    if (MyEditStr.Length() > 0) // There is something in the string
    {
        // AnsiStrings start at 1 instead of 0. 
        char MyChar = MyEditStr[1]; //This takes the first character.
        if (MyChar == 'T') led_off();
    }
}
//---------------------------------------------------------------------------



James P. Cottingham
I'm number 1,229!
I'm number 1,229!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top