Access to IDispatch Access Listing in XE2

We are using the old code (ComLib.pas created by Binh Ly), so we can use the enumeration interface on the object (OleVariant):

type TDispNewEnum = dispinterface ['{97079E31-6957-11D2-9154-0000B4552A26}'] // dummy property _NewEnum: IUnknown readonly dispid -4; // DISPID_NEWENUM function _NewEnumFunc: IUnknown; dispid -4; // DISPID_NEWENUM end; procedure TEnumVariant.AttachUnknown (const Unk: IUnknown); var pDisp: IDispatch; _NewEnumPropFailed: boolean; Unknown: IUnknown; begin Detach; Unknown := Unk; { extract IEnumVariant } if (Unknown <> nil) then begin { try IEnumVariant } if not (Succeeded (Unknown.QueryInterface (IEnumVariant, FEnumVariant))) then begin FEnumVariant := nil; // safety! { test _NewEnum prop and _NewEnum func } if (Succeeded (Unknown.QueryInterface (IDispatch, pDisp))) then begin _NewEnumPropFailed := False; try //property _NewEnum Unknown:=TDispNewEnum(pDisp)._NewEnum; // <---- RAISES EXCEPTION ----- if not (Succeeded(Unknown.QueryInterface(IEnumVariant, FEnumVariant))) then FEnumVariant := nil; // safety! except _NewEnumPropFailed := True; end; { except } 

This code works with Delphi 2010 and 2007, but not with XE2. In the line marked above (with the comment "EXCEPTION OF EXPENSES"), we get an exception:

Project x.exe raised exception class $ C0000005 with message access violation at 0xbaadf00d: reading address 0xbaadf00d '.

The object passed inside has the TDispNewEnum interface, so an exception should not occur (as is the case with Delphi 2010 and 2007).

Suggestions? Thank.

+3
delphi delphi-xe2 idispatch
Oct 24 '11 at 11:35
source share
1 answer

The memory address 0xbaadf00d is a pseudo memory address, which means "BAD FOOD" (look at the hexadecimal characters). This is typically used by code when requesting incorrect interfaces or calls.

What if you change the line to:

 pDisp: TDispNewEnum; ... if (Succeeded (Unknown.QueryInterface (IDispatch, pDisp))) then begin _NewEnumPropFailed := False; try //property _NewEnum Unknown:= pDisp._NewEnum; ... 

which makes sense to me.

I noticed some undocumented changes in the XE2 interface binding. Perhaps the previous code with a forced type ( TDispNewEnum(pDisp) ) no longer works because of this.

+5
Oct 24 '11 at 12:42
source share



All Articles