[SOLVED] Set focus on edit box (TCDEdit) lazarus / 61-Beginners ---------------------------------------------------------------------- tudi_x · 2016-07-08 06:57 Hi, I am trying to set focus to an edit box that is part of a tool bar as per the below code. The tool bar shares Form1 with some buttons. Unfortunately the focus remains on the first created button and does not shift to the edit box. Could you please help with how to set focus on a tool bar element? Thank you Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i PROCEDURE TForm1.AddTCDEdit(ALeft, ATop, ATag, AWidth : INTEGER; AParent : TWinControl; AName, AText, AHint : STRING; AFocus : BOOLEAN = False);VAR  theedit : TCDEdit; BEGIN  theedit := TCDEdit.Create(AParent);  theedit.Parent := AParent;  theedit.Name := AName;  theedit.Tag := ATag;  theedit.Left := ALeft;  theedit.Width := AWidth;  theedit.Top := ATop;  theedit.Visible := True;  theedit.ShowHint := True;  theedit.Hint := AHint;  theedit.Text := AText;   IF AFocus THEN  BEGIN    theedit.TabStop := True;    theedit.TabOrder := 0;  //try to set focus conditions when edit box is created  END;   _theLeft := _theLeft + AWidth;END; ---------------------------------------------------------------------- howardpc · 2016-07-08 07:18 What does Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i theedit.SetFocus;do for you? ---------------------------------------------------------------------- tudi_x · 2016-07-08 08:42 With: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  IF AFocus THEN  BEGIN    theedit.SetFocus;    //theedit.TabStop := True;    //theedit.TabOrder := 0;  END;   I get the attached error. Please advise. ---------------------------------------------------------------------- rvk · 2016-07-08 10:07 At what point are you calling TForm1.AddTCDEdit() ?? If it's in the Form1.FormCreate() then the form isn't visible yet and you can't use focus. You can, however, use ActiveControl. Is contains the control which will become focused on first show. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if AFocus thenbegin  ActiveControl := theedit;  //theedit.TabStop := True;  //theedit.TabOrder := 0;end; ---------------------------------------------------------------------- tudi_x · 2016-07-08 14:16 Thank you! Now it worked.