Bernard 20 Posted October 25, 2019 Hello All, I have had an annoying issue in Delphi 10.3.2 setting focus back to a TFileListBox component after loading a file into an ActiveX control. Here is the code for the Click on the FileListBox procedure TfrmCAD.flbCadClick(Sender: TObject); begin LoadFile; flbCAD.SetFocus; end; On execution I would expect the focus to return to the flbCAD TFileListBox control. This does not happen. If I do the following code it does... procedure TfrmCAD.flbCadClick(Sender: TObject); begin LoadFile; btnDetect.SetFocus; flbCAD.SetFocus; end; Is this a bug in the VCL or am I doing something wrong? Thanks Share this post Link to post
Uwe Raabe 2064 Posted October 25, 2019 Doesn't the control already has the focus during the OnClick event? In that case a WM_SETFOCUS message might not be sent. Share this post Link to post
David Heffernan 2353 Posted October 25, 2019 What happens if you don't call LoadFile? Share this post Link to post
Lars Fosdal 1793 Posted October 26, 2019 Is it just me, or does it seem to be slightly different behavior for Focus and BringToFront in Windows 10 1809 and later? I've had several experiences with Application modal windows popping up behind the main window, and it has not only been my own Delphi apps. Starting a Delphi App in the IDE for debugging, would leave the app running behind the BDS now and then. I've had MSSQL Server Management Studio 17.x become unusable with a popup locked behind its main window when left running overnight, on several occasions. 1 Share this post Link to post
David Heffernan 2353 Posted October 26, 2019 That's not an issue with focus. It's an issue with window owner, or popup parent in VCL terminology. Share this post Link to post
Bernard 20 Posted October 26, 2019 Hi Guys thanks for the swift replies and sorry for the delay in getting back to you all. When I do not call the loadfile; Focus remains on the TFileListBox component as is expected; When I do call the Loadfile on its own... The loadfile loads a cadfile into an activeX component and at this point focus is lost. I have also noticed that, at the point focus is lost, the tab button no longer gives focus to any of the other controls on the form. The activex control is a visual control EWDraw 3D. Is there something I am missing in the activeX end. Do I need to catch the tab key and send messages from its keyboard event? Share this post Link to post
David Heffernan 2353 Posted October 26, 2019 Well, I guess it's clear now that the issue is not Delphi, but rather what your ActiveX control does. Perhaps it's worth asking the vendor. Share this post Link to post
aehimself 399 Posted October 26, 2019 ...ooooor the focus actually stays on the button, it's just not redrawn properly. ActiveX controls work in strange ways (I still have active / not active issues with embedded MSTSC controls up to this day...) You can verify this by comparing form..ActiveControl with your button. Share this post Link to post
Guest Posted October 26, 2019 2 hours ago, Bernard said: Is there something I am missing in the activeX end. Ahhh... the old ActiveX. Well. I think (and i might be mistaken) that these ActiveX-related thingies are legion and that the workaround are prominent in sources like TWebBrowser and the like. I avoid these things as much as i can, but i have a lot of murky memories of having to fiddle with interfaces (COM) and a sleuth of other trickery. Dig in to other projects using ActiveX, i guess you'll find comments and workarounds galore pertaining to your issue. Share this post Link to post
PeterBelow 239 Posted October 27, 2019 19 hours ago, Bernard said: Hi Guys thanks for the swift replies and sorry for the delay in getting back to you all. When I do not call the loadfile; Focus remains on the TFileListBox component as is expected; When I do call the Loadfile on its own... The loadfile loads a cadfile into an activeX component and at this point focus is lost. I have also noticed that, at the point focus is lost, the tab button no longer gives focus to any of the other controls on the form. The activex control is a visual control EWDraw 3D. Is there something I am missing in the activeX end. Do I need to catch the tab key and send messages from its keyboard event? That sounds as if the form is no longer the foreground window after the ActiveX control hasloaded the file. Try to add a BringToFront; after the LoadFile line. Share this post Link to post
Bernard 20 Posted October 28, 2019 Tried BringToFront after the LoadFile Command and I am still getting the same issue. I accept there is a good chance this is a vendor issue. I am going to stick with my workaround at the minute... procedure TfrmCAD.flbCadClick(Sender: TObject); begin LoadFile; btnDetect.SetFocus; flbCAD.SetFocus; end; and send a bug report to the vendor. I appreciate all the help guys. Share this post Link to post