0
votes

I am having problem with Firemonkey TEdit Uppercase in Android.

Code:


procedure TFormMain.Edit1KeyDown(Sender: TObject; var Key: Word;
  var KeyChar: Char; Shift: TShiftState);
begin
    KeyChar := UpCase(KeyChar);
end;

In Win32 it works but in Android it's not working.

2
We don't know where this code is, in what context it runs.David Heffernan
I added it in Edit1KeyDownuser1041170
Please edit the Q to include the codeDavid Heffernan

2 Answers

3
votes

You have to use ChangeTracking event. It works fine

This code works on Android

procedure TFormMain.Edit1Typing(Sender: TObject);
begin
  Edit1.Text:=AnsiUpperCase(Edit1.Text);
  Edit1.GoToTextEnd;
end;

This code works on windows:

procedure TFormMain.Edit1ChangeTracking(Sender: TObject);
var
  thetext: String;
begin
  thetext := Edit1.Text;
  Edit1.OnChangeTracking := nil;
  Edit1.Text := '';
  Edit1.Text := AnsiUpperCase(thetext);
  Edit1.OnChangeTracking := Edit1ChangeTracking;
  Edit1.GoToTextEnd;
end;
0
votes

Use ToUpper (Documentation) or AnsiUpperCase (Documentation) for strings.

UPDATE: Why are you using OnKeyDown? According to Documentation you must use OnChangeTracking: "This event provides the first opportunity to respond to modifications the user brought to the text of the edit control."

So put in OnChangeTracking something like

procedure TFormMain.Edit1ChangeTracking(Sender: TObject);
begin
  Edit1.text:= AnsiUpperCase(Edit1.text);
end;