FMX下Edit只能输入数字

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  var KeyChar: Char; Shift: TShiftState);
var
  i: Boolean;
begin
  i := (keyChar <= #8) or (KeyChar<=#8) and (KeyChar<#48) or (KeyChar >#57) ;
  if i then
    keyChar := #0;
//   if not (keyChar in ['0'..'9',#13]) then KeyChar :=#0; end;

 在OnKeyDown中判断KeyChar的条件,以前delphi7里一般都在OnKeyPress事件下写

if not (key in ['0'..'9',#13]) then Key :=#0;

XE的FMX里没有OnKeyPress事件,一次在OnKeyDown下写,而Key参数是Word类型,所以要用到KeyChar

 

posted @ 2016-01-08 18:51  王云盼  阅读(634)  评论(0编辑  收藏  举报