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
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
// 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
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