Calling AddInModule from outside

Add-in Express™ Support Service
That's what is more important than anything else

Calling AddInModule from outside
How to call custom AddInModule methods/properties from TaskPane 
Michał Głębowski




Posts: 42
Joined: 2015-06-08
Dear Sirs,

I have my AddIn (for Excel) and TaskPane (in separate units).
I have created some properties in public section of my AddIn.
I'd like to use these properties from my TaskPane. I can't find, how to call my TAddInModule instance.
Usualy in VCL application I can call Form1 (which is an instance of TForm1 declared in var).
Here I can't see any entry like this:

var
  AddInModule: TAddInModule;


Is there any solution and is it good idea to use such properties (instead of global variables)?

Michal
Posted 30 Jun, 2015 15:14:43 Top
Andrei Smolin


Add-in Express team


Posts: 14138
Joined: 2006-05-11
Hello Michał,

Please see TadxOlForm.AddinModule.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 01 Jul, 2015 02:46:27 Top
Michał Głębowski




Posts: 42
Joined: 2015-06-08
I had problem with reaching AddInModule from my TaskPane and hopefully found the solution myself by fiddling in docs. I can use in my TaskPane:

TAddInModule(AddInModule).HostApp


Hope this is proper approach.
Thank you.
Posted 01 Jul, 2015 17:11:31 Top
Andrei Smolin


Add-in Express team


Posts: 14138
Joined: 2006-05-11
Thank you, Michał. That's what I was trying to tell; referring to TadxOlForm was a mistake. Also note that TadxExcelTaskPane provides the ExcelApp property.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 02 Jul, 2015 02:35:33 Top
Michał Głębowski




Posts: 42
Joined: 2015-06-08
Dear Andrei,
I have another similar question.
Is it possible to get my AddIn instance object handler from my own unit/class in the project?
Not from task pane where - as you told, I could use ExcelApp. I have no source code thus can't resolve myself.

Or simpler, to get ExcelApp from my separate class/unit.

Michal
Posted 03 Jul, 2015 04:37:03 Top
Andrei Smolin


Add-in Express team


Posts: 14138
Joined: 2006-05-11
Hello Michał,

You have two ways. You can pass the ExcelApp when constructing an instance of that class. Or, you can declare a global variable in the add-in module, set it to self in the add-in module's OnInitialize event and use that variable globally.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 06 Jul, 2015 07:12:37 Top
Michał Głębowski




Posts: 42
Joined: 2015-06-08
Thank you,
I was doing it already both ways, but thought any simpler way without creating another variable.
Thank you
Posted 06 Jul, 2015 07:53:24 Top
Andrei Smolin


Add-in Express team


Posts: 14138
Joined: 2006-05-11
You are welcome.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 06 Jul, 2015 08:53:08 Top
Michał Głębowski




Posts: 42
Joined: 2015-06-08
Dear Andrei,

I tried once to assign my own ExcelApp from ExcelRange (in my own form code), it does not work. Can you explain, why it is wrong approach?

uses Excel2000;

function Run(ARange: ExcelRange): Boolean;
var
  ExcelApp : TExcelApplication;
begin
  ExcelApp := TExcelApplication(ARange.Application);
  if ExcelApp.ActiveWindow = nil then exit; // this line makes program (dll) to terminate
  ...


Michał
Posted 17 Jul, 2015 04:53:56 Top
Andrei Smolin


Add-in Express team


Posts: 14138
Joined: 2006-05-11
Hello Michał,

TExcelApplication is a class; you can't cast the interface returned by ARange.Application to a class. Try using TExcelApplication.ConnectTo() instead.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 17 Jul, 2015 08:27:47 Top