Firemonkey TEdit Uppercase

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.


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;

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;
链接地址: http://www.djcxy.com/p/60480.html

上一篇: MacRuby xcode标签不起作用

下一篇: Firemonkey TEdit大写