Edit.SetFocus in laz4android lazarus / 31-LCL ---------------------------------------------------------------------- polypress · 2017-03-26 11:14 I think this is the correct part of the forum for this subject, but if not, then please advise. I would like to set focus on an edit control as soon as the app is started, but the Edit1.setFocus does not work. I have tried ActivityControl:=Edit1;, Edit1Click(Sender);,  Edit1.Focused;, Edit1.CanFocus;, SendMessage(Edit1.Handle, $0001, 0, 0);,  Edit1.Perform(EM_LINEINDEX, 1, 0);, Edit1.PerformTab(true);,  Edit1.Text:='  ';, Edit1.SelectAll; but none will send focus to Edit1; it will only focus when the control is clicked. I have studied LCLActivity.java to try to identify a solution in this. I have found requestFocus and setFocusableInTouchMode(true); but do not know how to reach these specifically in code for Edit1. Does anyone have a solution to achieve Edit1.setFocus, or provide a detailed tutorial on LCLActivity.java to enable a solution? Any contributions would be gratefully received. Regards ---------------------------------------------------------------------- ASerge · 2017-03-26 13:57 Quote from: polypress on March 26, 2017, 01:14:35 pmI would like to set focus on an edit control as soon as the app is started, but the Edit1.setFocus does not work. I have tried ActivityControl:=Edit1; Last valid: Form.ActiveControl := Edit1 Need the source code to find why is not working for you ---------------------------------------------------------------------- polypress · 2017-03-26 14:37 Thanks for your reply. I've tried with Form1.ActiveControl:=Edit1; but it still doesn't work. The relevant part of the code is as follows :- procedure TInvoicer1.Button9Click(Sender: TObject); begin   if (Button9.Caption='Show') then begin                               Button9.Caption:='Hide';                               AlStringGrid6.Visible:=true;                               HideKeys;                               end else begin                               Button9.Caption:='Show';                               AlStringGrid6.Visible:=false;                               doSound;                               Edit1.SetFocus;                               ActiveControl:=Edit1; //                              Edit1.Focused; //                              Edit1.CanFocus; //                              SendMessage(Edit1.Handle, $0001, 0, 0); //                              Edit1.Perform(EM_LINEINDEX, 1, 0); //                              Edit1.PerformTab(true); //                              Edit1.Text:='Here'; //                              Edit1Click(Sender); //                              Edit1.SelectAll;                               ShowKeys;                               end; end; The doSound;, HideKeys;, ShowKeys; work perfectly well; it's just the Edit1.SetFocus; etc. which don't work; I have tried it on a much smaller, basic app and get the same result. Regards ---------------------------------------------------------------------- ASerge · 2017-03-26 14:51 Try only one form with two Edit1, Edit2 and only one line of code ActiveControl := Edit2. ---------------------------------------------------------------------- polypress · 2017-03-28 08:39 I keep getting "error in script" when I write this for each character written. Is it a website problem or a problem on my computer. I have tried as you suggest, ASerge, but still get the same result - no focus until control is clicked. Regards ---------------------------------------------------------------------- polypress · 2017-04-04 08:27 Does anyone understand the logic of the LCLActivity.java code sufficiently to explain how each control (in particular, EditText control) is accessed? If I can understand this, then I hope I should be able to set this to focus by the "requestFocus" method. I have tried understanding the logic of the code, but cannot follow it through. Quote from: polypress on March 28, 2017, 10:39:57 amI keep getting "error in script" when I write this for each character written. Is it a website problem or a problem on my computer. The problem of "error in script" seems to have disappeared now. Regards