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事件下寫spa

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

XE的FMX裏沒有OnKeyPress事件,一次在OnKeyDown下寫,而Key參數是Word類型,因此要用到KeyChar orm

相關文章
相關標籤/搜索