DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: jeff1314
今日帖子: 21
在线用户: 12
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/30 8:24:19
标题:
my NEW homemade... NEW: How to move to next TEdit or any other control on FMX form? by Emailx45 浏览:941
加入我的收藏
楼主: How to move to next TEdit or any other control on FMX form? by Emailx45

now it's not necessary code on form.!
just put your "Edits" on the form or any other container!

note: each group of "Edits" have a "parent", and works independently each other parent.

Ex.: 3 groups for 11 edits:
- 1 form have 4 Edits (<<Enter>> key will works about this 4 edits)
- 1 panel have 2 Edits (<<Enter>> key will works about this 2 edits)
- 1 Edit have 5 Edits (edit into edit) (<<Enter>> key will works about this 5 edits)

----------
unit uView.FormMain;

interface

uses
  System.SysUtils,
  System.Types,
  System.UITypes,
  System.Classes,
  System.Variants,
  FMX.Types,
  FMX.Controls,
  FMX.Forms,
  FMX.Graphics,
  FMX.Dialogs,
  FMX.Controls.Presentation,
  FMX.Edit, //Sorry, really it's necessary at end
  FMX.Layouts,
  FMX.ListBox,
  FMX.StdCtrls,
  FMX.Memo.Types,
  FMX.ScrollBox,
  FMX.Memo,
  uMyNewTEdits;   // <---- using my new TEdit definition

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    ComboBox1: TComboBox;
    ListBox1: TListBox;
    Edit3: TEdit;
    Label1: TLabel;
    ComboBox2: TComboBox;
    Memo1: TMemo;
    Panel1: TPanel;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    procedure Edit3KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
  private
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

// not necessary any code on "KeyDown" event... but if can have it if needs!
procedure TForm1.Edit3KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
  ShowMessage('Hello World from Edit3...');
end;

end.

----------

unit uMyNewTEdits;

interface

uses
  System.Classes,
  FMX.Edit;

type
  TEdit = class(FMX.Edit.TEdit)
  protected
    procedure KeyDown(var AKey: Word; var AKeyChar: System.WideChar; AShift: TShiftState); override;
  end;

implementation

uses
  System.SysUtils,
  System.UITypes,
  FMX.Types,
  FMX.Controls;

var
  MyArrayEdits: TArray<TEdit>; // all edits on its parent!

  { TEdit }

function MyFindMyNextEditIndex(ACurrentEdit: TEdit; AShift: TShiftState): integer;
begin
  result := -1;
  //
  for var i: integer := 0 to (high(MyArrayEdits)) do
    if (MyArrayEdits[i] = ACurrentEdit) then
    begin
      if (AShift = [ssShift]) then
        result := i - 1
      else
        result := i + 1;
      //
      Break;
    end;
  //
  if (result < 0) then
    result := high(MyArrayEdits)
  else if (result > high(MyArrayEdits)) then
    result := 0;
end;

procedure TEdit.KeyDown(var AKey: Word; var AKeyChar: System.WideChar; AShift: TShiftState);
var
  MyNextEditIndex: integer;
begin
  inherited;
  //
  MyArrayEdits    := []; // starting...from zero edits.
  MyNextEditIndex := -1; // avoid random value...
  //
  if not(AKey = vkReturn) then
    exit;
  //
  if not(Self.Parent = nil) and (Self.Parent.ChildrenCount > 0) then
  begin
    for var i: integer := 0 to (Self.Parent.ChildrenCount - 1) do
      if (Self.Parent.Children[i] is TEdit) then
        MyArrayEdits := MyArrayEdits + [TEdit(Self.Parent.Children[i])]; // catch the "edits" on "container"=> Parent
    //
    if (Length(MyArrayEdits) > 1) then // there is more than 1 "edit"
    begin
      MyNextEditIndex := MyFindMyNextEditIndex(Self, AShift); // who's the next?
      //
      TEdit(MyArrayEdits[MyNextEditIndex]).SetFocus;
      //
      // just for test on screen...
      TEdit(MyArrayEdits[MyNextEditIndex]).Text := Format('%s_Idx_%d', [TEdit(MyArrayEdits[MyNextEditIndex]).Name, MyNextEditIndex]);
    end;
  end;
end;

end.
此帖子包含附件:
PNG 图像
大小:76.1K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/30 8:55:10
1楼: remember:

TEdit is a TControl... then, you can adapt TControl class to similar usage!

TControl( xxxx ).SetFocus  => it should works for any TControl like:
TButton, TEdit, TMemo, TListBox, etc...
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2022/4/30 11:19:44
2楼: 翻译一下意思:

做一个 procedure TEdit.KeyDown 方法,在这个方法里面,对界面上的所有 Edit 做一个循环,找到下一个,让它 SetFocus;

然后,只要给每个 Edit1, Edit2 的 OnKeyDown 事件,指向这个 TEdit.KeyDown 方法,就可以了.
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/30 22:05:59
3楼: If want that ALL CONTROLs have a "ENTER as TAB", you need works on "TControl" class, not just TEdit, TMemo, etc... use TCONTROL class!!!

Then, my idea above is just a sample as you can do it!

You will need changes it using "TControl" as your job-object , not TEdit.
as all controls inherit from TControl, then, you can use "SetFocus" to move to next control.

SetFocus, in fact, use "Root.NewFocusedControl(Self);"
Root = object parent of current control
NewFocusedControl = find the next control in Root
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行70.3125毫秒 RSS