Book a Demo

Author Topic: GetContextItem cause access violation on D7  (Read 4865 times)

Ondrej Kolenaty

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
GetContextItem cause access violation on D7
« on: March 04, 2008, 06:00:30 pm »
Hello,

 I am trying to customize my addin menu based on selected item in GetMenuItems event. I use this code:
Code: [Select]
function TEARPlugin.EA_GetMenuItems(const aRepository: IDispatch;
  const aLocation, aMenuName: WideString): OleVariant;
var obj : IDispatch;
begin
  Repository(aRepository).GetContextItem(obj); // "Repository" is IDualRepository synonym from EA_TLB
  .
  .
  .
end;

But this cause a acces violation error. Please, can anyone tell me what I do wrong?

I have D7, WinXP, EA7.1 (I even tried EA7.0 with freshly imported Type Library, but without success).

Thanx.

Ondrej Kolenaty

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
Re: GetContextItem cause access violation on D7
« Reply #1 on: March 05, 2008, 05:55:38 pm »
The typecast is wrong. Corect code is:

Code: [Select]
function TEARPlugin.EA_GetMenuItems(const aRepository: IDispatch;
 const aLocation, aMenuName: WideString): OleVariant;
var obj : IDispatch;
begin
 (aRepository as Repository).GetContextItem(obj);
 .
 .
 .
end;

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: GetContextItem cause access violation on D7
« Reply #2 on: March 06, 2008, 03:06:57 am »
Still, you should report the first instance - with the incorrect syntax - as a bug. Please see the note below.

EA should produce an error message rather than suffer an access violation. This would let your code signal you, handle the error, terminate, or any combination thereof as appropriate.

NOTE: I am assuming that you meant that EA crashed with an access violation error, which is the result of most such errors. If EA merely reported the error back to your code (which might have handled it) then this is the appropriate result, and no report should be filed.
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: GetContextItem cause access violation on D7
« Reply #3 on: March 06, 2008, 07:09:47 am »
I could be wrong, but if the typecast is incorrect then the code won't even get to EA, and it won't be EA produced the access violation.