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

but, the main idea is:
-- to know the current TEdit in focus!
-- to know how many TEdit controls exists on form!
-- move to next TEdit control.

of course, it would be better create a "helper class" or same a new TEdit implementation and use "interfaces/procedures of TControl" or any other "professional" pattern to do it. But, it's too late and I need sleep... :)

any way, it's works with any TControl on form.!


var
  Form1: TForm1;

implementation

{$R *.fmx}

uses
  System.Generics.Collections;

var
  MyArrayEdit: TArray<TEdit>;

function MyFindNextTEdit(AEditCurrent: TEdit): integer; // index of TEdit on MyArrayEdit
begin
  result := -1;
  //
  if (AEditCurrent = nil) then
    exit;
  //
  for var i: integer := 0 to high(MyArrayEdit) do
    if (MyArrayEdit[i] = AEditCurrent) then
      exit(i);
end;

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
var
  MyNextEditIndex: integer;
begin
  (* // simple solution find on internet!!!

    if (Key = vkReturn) then
    begin
    Key := vkTab;
    KeyDown(Key, KeyChar, []); // the problem: next control can be any control!!!
    end;
  *)
  //
  MyNextEditIndex := -1;
  //
  if (Key = vkReturn) then
  begin
    if (Self.ActiveControl is TEdit) then
    begin
        MyNextEditIndex := MyFindNextTEdit(TEdit(Self.ActiveControl));
      //
      inc(MyNextEditIndex);
      //
      if (MyNextEditIndex > high(MyArrayEdit)) then
        MyNextEditIndex := 0;
      //
      Self.ActiveControl := TEdit(MyArrayEdit[MyNextEditIndex]);
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  for var i: integer := 0 to (Self.ChildrenCount - 1) do
  begin
    if (Self.Children[i] is TEdit) then
      MyArrayEdit := MyArrayEdit + [TEdit(Self.Children[i])];
  end;
  //
  if Length(MyArrayEdit) > 0 then
  begin
    TArray.Sort<TEdit>(MyArrayEdit); // trying sort it if necessary
    //
    // just for test the TEdit names
    for var i: integer := 0 to (high(MyArrayEdit)) do
      ListBox1.Items.Add(TEdit(MyArrayEdit[i]).Name);
  end;
end;

end.

good luck
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/29 13:12:47
1楼: how to use:

1) just use Object Inspector in another TEdits on event "KeyDown"...
此帖子包含附件:
PNG 图像
大小:20.6K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/4/29 16:43:17
2楼: 谢谢,但如果下一个控件是combobox呢?
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/29 21:56:54
3楼: my sample is "defining automaticaly" all TEdit (objects in my array) using "For in..."

if you dont want some like this, you can define yourself (manually).

MyArrayEdit := MyArrayEdit + {}
[MyEdit1, MyButton2, MyEdit14, MyMemo79,etc.... ];

then, dont "Sort it" like my sample!

note: of course, you need adapt the event KeyDown for your complexity!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/29 22:07:59
4楼: // if length( MyArrayEdit ) > 0 then .... to avoid "access violation"

if (Self.ActiveControl is TEdit) then
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/30 9:01:45
5楼: my sample changing the "OnKeyDown" event on TEdit class ... just a "add-on" on the class!

http://bbs.2ccc.com/topic.asp?topicid=628787
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行80.07813毫秒 RSS