Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Problem with TEdit 4 months 1 week ago #18095

  • Vbxler
  • Vbxler's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 61
  • Thank you received: 1
Hello everyone,

I have a problem with the TEdit Control, I use this control to enter the user and password.
The user can only enter certain characters, which is evaluated during the KeyPress event.
If the user entered a special character (like a German umlaut) then I don't get the correct ASCII code.
//----------------------------------------------------------
// special character
//-----------------
//ö = #246
//ä = #228
//ü = #252
//Ö = #214
//Ä = #196
//Ü = #220
//ß = #223
//----------------------------------------------------------
procedure TfrmLogIn.txtBenutzernameKeyPress(Sender: TObject; var Key: char);
begin
  if Key = #13 then
    txtPasswort.SetFocus
  else if not (Key in [#8, ' ', '_', #246, #228, #252, #214, #196, #220, #223, 'a'..'z', 'A'..'Z', '0'..'9']) then
    begin
      Key := #0;
      Beep;
    end;
end;
If I press 'ü' then I get '?' as Key = 63 '?'

Has anything fundamental changed here? This code worked without any problems about a year ago.

Thank you for your help.
 

Please Log in or Create an account to join the conversation.

Problem with TEdit 4 months 4 days ago #18103

  • Vbxler
  • Vbxler's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 61
  • Thank you received: 1
I think I have found the solution,

I have to use procedure UTF8KeyPress instead of procedure KeyPress to be able to evaluate the special characters:
procedure TForm1.txtPasswortUTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
var
  myKey   : char;
  myUTF8  : utf8string;
  myANSI  : ansistring;
begin
  myUTF8  := utf8key;
  myANSI := lconvencoding.UTF8ToCP1252 (myUTF8);
  if (length(myANSI) = 1) then
  begin
    myKey := myANSI[1];

    if myKey = #13 then
       Application.MessageBox('Enter', '', 0)
    else if not (myKey in [#8, ' ', '_', #246, #228, #252, #214, #196, #220, #223, 'a'..'z', 'A'..'Z', '0'..'9']) then
      begin
        UTF8Key := #0;
        Beep;
      end;
  end;
end;

Please Log in or Create an account to join the conversation.

Problem with TEdit 4 months 4 days ago #18105

  • Matis A.
  • Matis A.'s Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1022
  • Thank you received: 140
Thanks Sir
have fun...
PilotLogic Core Programmer

Please Log in or Create an account to join the conversation.

  • Page:
  • 1