I modified project creating TLogin_Dld immediately after MainForm creation, so when mainfrm event is activate creation of Login_Dlg is done.
my project : begin Application.Initialize; Application.Title := 'Applicazione Gestionale '; Application.MainFormOnTaskbar := True; Application.CreateForm(TfrmMain, frmMain); Application.CreateForm(TLogin_dlg, Login_dlg); Application.Run; end.
MainForm, FormActivate : if not assigned(Login_dlg) then Login_dlg := TLogin_dlg.Create( nil ); (login may be called from menu when user want change DB Connection)
Login_Dlg : procedure TLogin_dlg.FormCreate(Sender: TObject); begin PostMessage(Handle,UM_SETFOCUS, 0, LPARAM(txt_username)); end;
procedure TLogin_dlg.FormActivate(Sender: TObject); var KeyState: TKeyboardState; begin Login_dlg.Top := 130; Login_Dlg.OnActivate := nil; Caption := Caption + ' - '+Server_nomefile; //note: Use VK_CAPITAL for Caps Lock GetKeyboardState(KeyState) ; //simulate key events (down + up) if (KeyState[VK_CAPITAL] = 1) then ShowMessage('Attenzione Caps Lock Inserito');
// txt_username.SetFocus;
end; -----------------------------------------------------------------------------------
When I start application, I get message : 'No VCL control with focus' and cursor is missing (if type anything no button is fired) when I click on TEdit cursor appears and msg 'No focus anywhere'
Same result if I decomment txt_username.SetFocus;
Regards Adalberto Baldini