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
|
|
Dmitry Kostochko
Add-in Express team
Posts: 2880
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.
|
|
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 |
|
Dmitry Kostochko
Add-in Express team
Posts: 2880
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.
|
|
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 |
|
Dmitry Kostochko
Add-in Express team
Posts: 2880
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.
|
|