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
// 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;
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.
此帖子包含附件: 大小:76.1K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
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
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