Cumartesi, Ağustos 11, 2018

Can not focus a disabled or invisible window!

My suggestion is:

procedure _setFocus(o: TObject);
var
   m: TMsg;
   c: Cardinal;
begin
   c := GetTickCount;
   // Wait max. 200 milliseconds...
   while not Application.Terminated and (GetTickCount - c > 200) do
      begin
         if (o is TWinControl) and 
            IsWindowVisible(TWinControl(o).Handle) and
            TWinControl(o).Enabled
         then
            begin
               TWinControl(o).SetFocus;
               break;
            end
         else if PeekMessage(m, 0, 0, 0, PM_REMOVE) then
            begin
               TranslateMessage(m);
               DispatchMessage(m);
            end;
      end;
   // As a matter of fact, the best way to do this is with THREAD.
   // Murat
end;
.
.
.
_setFocus(edit1);