1

Is it bug of VCL?? Non modal form cannot receive input in Excel COM Add in. But the very same code of C# works fine.

Demo: https://drive.google.com/open?id=1eKermBZdgXdT7KtfJeZWxYiUwjDNRAst

C# Demo: https://drive.google.com/open?id=1tdcgkbHU8cExVhHrmFsQeA5oqjlzxN3k

Delphi Code:

procedure TDelphiAddIn1.OnStartupComplete(var custom: PSafeArray);
var
  LForm: TForm1;
begin
  LForm := TForm1.Create(nil);
  LForm.Show;
end;

C# Code:

public void OnStartupComplete(ref System.Array custom)
{
    new Form1().Show();
}

Delphi Version: Delphi 10.1 Berlin update2 (1. Steps:Compile the project. 2. Open cmd as Administrator, use regsvr32.exe DLLPath to register the output DLL 3.Open Excel )enter image description here

Chang
  • 179
  • 1
  • 9
  • If the modal-less Form is being shown in the context of a thread inside the Excel process, there is likely no message loop running to let the VCL process input messages. Displaying a VCL Form modally runs its own message loop. That, or your video implies that Excel is stealing the user input. – Remy Lebeau Jan 25 '18 at 01:27
  • Modal form works correctly. But user need interact with Excel when my form is shown( pick cell from excel, and select the active cell). can i let vcl form behave like the .net form ? – Chang Jan 25 '18 at 01:40
  • Excel has a terrible habit of stealing user input. I have issues with it all the time, not even related to programming. – Jerry Dodge Jan 25 '18 at 17:01
  • My WinZip cannot open your Delphi demo and in any case you should not post a question which requires downloads from an external source, the q should be self-contained instead. Anyway, are you using a 3rd party library like https://www.add-in-express.com/?utm_campaign=adx1&utm_source=adx&utm_medium=search&gclid=EAIaIQobChMI75yxkfrz2AIVSzobCh2CzgBHEAAYASAAEgL8KPD_BwE to implement your add-in. – MartynA Jan 25 '18 at 20:32
  • It seems my winrar version is too high. I updated the link with zip format. The issue cannot be described by some lines of code, so i upload it to google drive. I'm not using add-in express, just implement the IDTExtensibility2 interface. ( but add-in express have the same issue) – Chang Jan 26 '18 at 01:17
  • Try to set Application.Handle := ExcelApp.HWND , but didn't solve it. – Chang Jan 29 '18 at 09:17
  • Still cannot solve this issue – Chang Feb 02 '18 at 02:42
  • @RemyLebeau After many searches, I think it's impossible to solve this in VCL. Since it needs start another UI thread and run message loop in it. – Chang Mar 01 '18 at 09:22

0 Answers0