[英]Delphi FMX edit controls inconsistencies - How to make a fast-entry form?
I have coded a Delphi FMX form for data entry on an Android app. 我编写了一个Delphi FMX表单,用于在Android应用上输入数据。 This consists of several controls arranged vertically and aligned with horizontal centers. 这包括几个垂直排列并与水平中心对齐的控件。 The controls are also all placed on a TVertScrollBox, so the controls can be scrolled into (and out of) view. 控件也全部放在TVertScrollBox上,因此控件可以滚动到(和退出)视图中。 There are a few TEdits, 2 TComboboxes, and 1 TComboEdit. 有一些TEdits,2个TComboboxes和1个TComboEdit。 I have also added the following code to my form 我还在表单中添加了以下代码
procedure TfrmMain.FormKeyDown(Sender: TObject; var Key: Word;
var KeyChar: Char; Shift: TShiftState);
begin
if Key = vkReturn then
begin
Key := vkTab;
KeyDown(Key, KeyChar, Shift);
end;
end;
Now this works fabulously for the TEdit controls in that the user can use the enter key (typically I set the TEdit.ReturnKeyType
property to Next) to navigate the list of controls, entering data for each one and hitting the enter key to move the focus to the next one. 现在,这对于TEdit控件非常有用,因为用户可以使用回车键(通常我将TEdit.ReturnKeyType
属性设置为Next)来导航控件列表,为每个控件列表输入数据并按下回车键以移动焦点到下一个。
There are 2 problems here. 这里有两个问题。
As soon as the control is a TCombobox, the virtual keyboard disappears. 一旦控件是TCombobox,虚拟键盘就会消失。 In other words, there is no .keyboardtype
or .ReturnKeyType
property on a TCombobox. 换句话说, .ReturnKeyType
上没有.keyboardtype
或.ReturnKeyType
属性。 So after selecting an entry for the combobox from the dropdown, they have to "reach in" and select the next control manually. 因此,在从下拉列表中选择组合框的条目后,它们必须“到达”并手动选择下一个控件。 Often they miss. 他们常常想念。
The TEditCombo is a strange descendent indeed. TEditCombo确实是一个奇怪的后代。 It has a .Keyboardtype
property, but it doesn't have a .ReturnKeyType
property. 它具有.Keyboardtype
属性,但它没有.ReturnKeyType
属性。 This has my users very confused because although they can type into this combobox, the return key doesn't say "Next" when this control has focus like it does on the TEdits. 这让我的用户非常困惑,因为虽然他们可以键入这个组合框,但当这个控件像TEdits那样有焦点时,返回键不会说“Next”。
How can I make all the controls on this form show the keyboard and have the "return key" move to the next control irrespective of the type of the current control or the next one? 如何使此表单上的所有控件显示键盘并将“返回键”移动到下一个控件,而不管当前控件的类型或下一个控件的类型?
Was I privileged to have programmed Windows apps using the VCL? 我有幸使用VCL编写了Windows应用程序吗?
On the Comboboxes and TComboEdits, add the following event handlers: 在Comboboxes和TComboEdits上,添加以下事件处理程序:
procedure TForm1.ComboBox1CanFocus(Sender: TObject; var ACanFocus: Boolean);
begin
Combobox1.DropDown;
end;
procedure TForm1.ComboBox1Exit(Sender: TObject);
var
keyboard: IFMXVirtualKeyboardService;
begin
keyboard := TPlatformServices.Current.GetPlatformService(IFMXVirtualKeyboardService) as IFMXVirtualKeyboardService;
if keyboard.HideVirtualKeyboard then
Label1.text := 'hidden';
end;
procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;
var KeyChar: Char; Shift: TShiftState);
begin
label1.Text := IntToStr(Key);
if Key = vkReturn then
begin
Key := vkTab;
KeyDown(Key, KeyChar, Shift);
end;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
Shift: TShiftState);
begin
label1.Text := IntToStr(Key);
if Key = vkReturn then
begin
Key := vkTab;
KeyDown(Key, KeyChar, Shift);
end;
end;
procedure TForm1.ComboBox1ClosePopup(Sender: TObject);
var
keyboard: IFMXVirtualKeyboardService;
MS: TmessageSender;
begin
keyboard := TPlatformServices.Current.GetPlatformService(IFMXVirtualKeyboardService) as IFMXVirtualKeyboardService;
if keyboard.showVirtualKeyboard(ComboBox1) then
Label1.Text := 'Shown';
MS := tmessageSender.Create;
try
Ms.SendMessage<TReturnKeyType>(MM_EDIT_RETURNKEYTYPE_CHANGED, TReturnKeyType.Next);
finally
MS.Free;
end;
end;
It works like this: 它的工作原理如下:
When the combobox receives focus, it immediately drops down. 当组合框获得焦点时,它会立即下降。
Immediately after the user selects an item from the dropdownlist, the Keyboard gets shown and it's return key display is changed to "Next". 用户从下拉列表中选择一个项目后,会立即显示键盘并将其返回键显示更改为“下一步”。
The keydown event handler of the combobox seems to intercept the return key, as there's no .keypreview
property in FMX forms, so it has it's own event handler to "change" the return key to a tab key, so that the next control (in tab order) gets focus. 组合框的keydown事件处理程序似乎拦截了返回键,因为在FMX表单中没有.keypreview
属性,因此它有自己的事件处理程序将“返回”键“更改”为tab键,以便下一个控件(在tab tab)获得焦点。
As the combobox gets exited (from), the keyboard is hidden. 当组合框退出(从)时,键盘被隐藏。
I cribbed the SendMessage code from the FMX.Edit.pas unit. 我从FMX.Edit.pas单元中抄袭了SendMessage代码。 It seems to work. 它似乎工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.