Disabled or Invisible Window can't be FOCUSED lazarus / 62-General ---------------------------------------------------------------------- Awesome Programmer · 2019-07-23 18:48 I don't understand why I am getting this. I start my program and program's main window is displayed. I then click on a button that window to open another window. Except this time the second window is opened with SHOWMODAL command. The second window pops up with no issue at all. However, As soon as I close the second modal window and then click on the main window, I get this DISABLED OR INVISIBLE WINDOW CAN'T BE SETFOCUS error. Then, my program crashes. 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 TMainFrm.Button1Click(Sender:TObject);var     teststr:string;begin       if SecondFrm.ShowModal=MrOk then           teststr:=SecondFrm.Label1.caption;              //This is what I have been trying and this workaround won't work at all.       MainFrm.Enabled:=true;       MainFrm.Visible:=true;       MainFrm.ActiveControl:=MainFrm;      end;... ---------------------------------------------------------------------- Thaddy · 2019-07-23 19:18 If a form is modal, you prevent any other form to respond - visually -. First the modal form has to close . You can set properties for  other forms, however they will propagate visually once the  modal form is closed. ---------------------------------------------------------------------- Awesome Programmer · 2019-07-23 19:26 Hi Thaddy Yes, you are right that the modal form is always the one on the very top of all the other form. Plus, you wouldn't have access to other forms until you close the showmodal form. My windows or forms behave as they should, but when I go back to the main form by first closing the modal form, I get this error. ---------------------------------------------------------------------- lucamar · 2019-07-23 19:58 Yu shouldn't have that problem unless the second form (the modal one) is not closing correctly. But in that case your code wouldn't pass from the   if SecondFrm.ShowModal=MrOk then .... Incidentally, this code: 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    MainFrm.Enabled:=true;   MainFrm.Visible:=true;   MainFrm.ActiveControl:=MainFrm;shouldn't be necessary. Once the modal form is closed the focus should revert to the caller wiyhout more ado. In any case, the usual setting order is: 1) Visible, 2) Enabled (which shouldn't have changed) and 3) ... don't set ActiveControl = form: it's allowed, because a form is effectively a control, but trying to set focus to a form makes the form try to "pass the ball" to its "ActiveControl", if set. You can see where that would lead There must be soemthing strange going on in your program because usually all that is needed is something like: 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 TMainFrm.ButtonClick(Sender: TObject);begin  if not Assigned(SecondFrm) then    SecondFrm := TSecondFrm.Create(Application);  if SecondFrm.ShowModal = mrOK then begin    {do something};  end;end; Can you show (or attach) a more complete example?