Strange happenings with WordApp

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

Strange happenings with WordApp
Same code in different procs, one works, one doesn't 
Nicholas Glasier


Guest


Something bizarre is happening.

I have two procedures, both in the _IMPL.pas file:


procedure ToDoCmmndBarControls2Click(Sender: TObject);
var
intf: IDispatch;
IDocs: Word2000.documents;
I: integer;

Begin
Showcomment(?Â?Ð?èStart of proc?Â?Ð?é);
Intf := WordApp.Documents;
Showcomment(?Â?Ð?èQuerying interface?Â?Ð?é);
Intf.QueryInterface(Word2000.Documents, IDocs);
.
.
.
//============================================
procedure DoIt(somevar: Widestring;);
var
intf: IDispatch;
IDocs: Word2000.documents;
I: integer;

Begin
Showcomment(?Â?Ð?èStart of proc?Â?Ð?é);
Intf := WordApp.Documents;
Showcomment(?Â?Ð?èQuerying interface?Â?Ð?é);
Intf.QueryInterface(Word2000.Documents, IDocs);
.
.
.
//============================================

As you can see they are identical (to begin with), the only difference is that the second is called from a Delphi form using a variable fAddinModule which is assigned TAddinModule in an override Create method for the form.
//============================================
Var fAddinmodule: TAddinModule;

constructor TEditDlg.Create(AOwner: TComponent);
begin
inherited Create(nil);
if AOwner is TAddInModule then
FAddInModule := AOwner as TAddInModule
else
FAddInModule := nil;
end;
//============================================

The first showcomments(?Â?Ð?èStart of proc?Â?Ð?é); displays in both cases

The first code works fine when called, it is actually used to load data into the form.
The second causes an exception when the intf is assigned WordApp.Documents, so the showcomments(?Â?Ð?èQuerying interface?Â?Ð?é); never displays.

I?Â?Ð?éve tried moving the second procedure next to the first in the interface section of IMPL.pas, and I tried making it published, but it still causes an exception.

I also tried using WordApp.Documents without an interface because the Count property is exposed, and then doing the intf later in the code, but the second procedure just don?Â?Ð?ét like WordApp.Documents at run-time.

I?Â?Ð?ém using build 2.3 preview with Delphi 7 pro and all updates, on XP Pro with all updates, and the only thing I?Â?Ð?éve done since writing the code for the first procedure is to open and try the Word context menu demo from your site.

Any thoughts on this, I?Â?Ð?ém flummoxed.
TIA Nick

Posted 14 Mar, 2005 02:25:56 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Nick,

The code snippets above are not enough.
I assume that first ToDoCmmndBarControls2Click procedire is a method of TAddInModule, am I right? And I don't see the WordApp variable declaration in the second procedure.







Posted 14 Mar, 2005 07:05:21 Top
Nicholas Glasier


Guest


Hi Dmitry,

They are both members of TAddinModule.
Sorry, I left that bit off the beginning of the second procedures heading, it should read: procedure TAddinModule.DoIt(Somevar: Widestring);

That's why there is no declaration for WordApp in the second procedure.
The second procedure is declared in the public section of TAddinmodules interface declaration.

Nick
Posted 14 Mar, 2005 14:34:02 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Nick,

Strange. What error message did you see when the exception occurred? Access violation at address 0? Could you please send your project for testing.



Posted 15 Mar, 2005 06:42:32 Top
Nicholas Glasier


Guest


Hi Dmitry,

It was an access violation, but whatever was causing was cured by deleting the entire procedure, saving the file, and then writing the procedure again.

Don't ask me why, I simply copied and pasted the same code as before, but it now works. Is there any history of Delphi having problems like this? I think it's definitely a Delphi problem, before I found the fix I tried rewriting the code so it wasn't called from the Form, but the problem was still there. I don't think Delphi's environment is as stable as it used to be since Microsoft headhunted some of Borlands top people, but it's still the best around for my money ;)

Regards Nick
Posted 15 Mar, 2005 16:08:02 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Nick,

Is there any history of Delphi having problems like this?

I don't know.

It was really a strange situation. But I am glad everything is working now.




Posted 16 Mar, 2005 06:06:03 Top