2018年3月1日星期四

Modeless form cannot receive key input in Excel Add-in developed by Delphi

To solve this problem, start another UI thread and run message loop in it is needed.

https://drive.google.com/file/d/1sQEdtRCSmXsPXBqbPPWAzJZPfGRsTJVQ/view?usp=sharing

Steps:
1.Compile MultipleUIThreadsinVCLGroup.groupproj
2.Open cmd as Administrator,use regsvr32 MultipleUIThreadsinVCL.DLL to register the Excel Add-in
3.Open Excel

This solves the following issue:
1. Modeless form cannot receive user input. If start message loop in VCL main thread, form can receive key input but all async function in Excel will be broken.
2.When click Excel work sheet, modeless form doesn't lose focus.
3.When modeless form is open, close Excel will cause crash, and then ask user whether to disable the add-in at next start of Excel.
4.Many other message related problems in Excel add-in.