Discussion:
Exception 'EIntfCastError' with Type library in Delphi 2007
(too old to reply)
Ivan
2008-07-25 12:58:15 UTC
Permalink
Exception 'EIntfCastError' with Type library in Delphi 2007

My project contains 1 package (MIPkg) and two executables (MiEx1) and
(MiEx2)
In the executable (MiEx1) i have created a type library (MiEx1.tlb)

Type library MiEx1_TLB.pas:

const
DVCMajorVersion = 1;
DVCMinorVersion = 0;
LIBID_DVC: TGUID = '{4E31D960-4E47-11D2-899A-0000C0C44D2F}';

IID_IAcabadoOLE:TGUID='{4E31D961-4E47-11D2-899A-0000C0C44D2F}';

CLASS_AcabadoOLE:TGUID='{4E31D962-4E47-11D2-899A-0000C0C44D2F}';
type
IAcabadoOLE = interface;
IAcabadoOLEDisp = dispinterface;

.......

implementation

uses ComObj;

class function CoAcabadoOLE.Create: IAcabadoOLE;
begin
Result := CreateComObject(CLASS_AcabadoOLE) as IAcabadoOLE;
end;

In AcabadoOle.pas is at (MiEx1) defines Class TAcabadoOle

TAcabadoOLE = class(TAutoObject, IAcabadoOLE)

In AcabadoOle.pas was added the initialization line

initialization

TAutoObjectFactory.Create(ComServer,TAcabadoOLE,Class_AcabadoOLE,ciMultiInstance,tmApartment);

Note: The "MiEx1_TLB.pas" is compiled in the package (MIPkg)

Operation:

1. Execute (MiEx2)
2. (MiEx2) execute (MiEx1)
3. At the initialize (MiEx1), runs the command TAutoObjectFactory
4. (MiEx2) attempt to create an object of class IAcabadoOle:

var
_Aole: IacabadoOle;
begin
_Aole := CoAcabadoOLE.Create.
....
end;

Failure

When run the line
CreateComObject(CLASS_AcabadoOLE) as IAcabadoOLE

Show Exception error message

Exception 'EIntfCastError' Interface not supported


Thanks.
Ivan.
Marc Rohloff [TeamB]
2008-07-25 13:49:23 UTC
Permalink
On Fri, 25 Jul 2008 14:58:15 +0200, Ivan wrote:

Ivan,

Please don't multi post. I deleted your other posts.

Have you tried :

var i:IUnknown;
i := CreateComObject(CLASS_AcabadoOLE);
without the typecast?

This looks like the COM object or server is not implemented correctly.
--
Marc Rohloff [TeamB]
marc -at- marc rohloff -dot- com
Ivan
2008-07-28 10:05:29 UTC
Permalink
Hi Marc,

I changed the role of create:

Create class function: IAcabadoOLE;

to

Create class function: IUnknown;
....
CoAcabadoOLE.Create class function: IUnknown;
Begin
Result: = CreateComObject (CLASS_AcabadoOLE);
End;

and replaced in the executable:

var
Abd: IAcabadoOLE;
Begin
Abd: = CoAcabadoOLE.Create;
Abd.Directory:= MIDIR;
...
End;

by:

var
i: IUnknown;
Abd: IAcabadoOLE;
Begin
i: = CoAcabadoOLE.Create;
Abd: = (i as IAcabadoOLE);
Abd.Directory:= MIDIR;
...
End;

**** Error in (i as IAcabadoOLE);

I have tried with:

var
i: IUnknown;
Abd: IAcabadoOLE;
Begin
i: = CoAcabadoOLE.Create;
Abd: IAcabadoOLE = (i);
Abd.Directory:= MIDIR;
...
End;

**** Error in "Abd.Directory:= MIDIR;"

thanks,


On Fri, 25 Jul 2008 10:49:23 -0300, "Marc Rohloff [TeamB]"
Post by Marc Rohloff [TeamB]
Ivan,
Please don't multi post. I deleted your other posts.
var i:IUnknown;
i := CreateComObject(CLASS_AcabadoOLE);
without the typecast?
This looks like the COM object or server is not implemented correctly.
Ivan
2008-07-28 10:08:33 UTC
Permalink
correction:

I have tried with:

var
i: IUnknown;
Abd: IAcabadoOLE;
Begin
i: = CoAcabadoOLE.Create;
Abd: IAcabadoOLE(i);
Abd.Directory:= MIDIR;
...
End;

**** Error in "Abd.Directory:= MIDIR;"
Post by Ivan
Hi Marc,
Create class function: IAcabadoOLE;
to
Create class function: IUnknown;
....
CoAcabadoOLE.Create class function: IUnknown;
Begin
Result: = CreateComObject (CLASS_AcabadoOLE);
End;
var
Abd: IAcabadoOLE;
Begin
Abd: = CoAcabadoOLE.Create;
Abd.Directory:= MIDIR;
...
End;
var
i: IUnknown;
Abd: IAcabadoOLE;
Begin
i: = CoAcabadoOLE.Create;
Abd: = (i as IAcabadoOLE);
Abd.Directory:= MIDIR;
...
End;
**** Error in (i as IAcabadoOLE);
var
i: IUnknown;
Abd: IAcabadoOLE;
Begin
i: = CoAcabadoOLE.Create;
Abd: IAcabadoOLE = (i);
Abd.Directory:= MIDIR;
...
End;
**** Error in "Abd.Directory:= MIDIR;"
thanks,
On Fri, 25 Jul 2008 10:49:23 -0300, "Marc Rohloff [TeamB]"
Post by Marc Rohloff [TeamB]
Ivan,
Please don't multi post. I deleted your other posts.
var i:IUnknown;
i := CreateComObject(CLASS_AcabadoOLE);
without the typecast?
This looks like the COM object or server is not implemented correctly.
Marc Rohloff [TeamB]
2008-07-28 12:54:54 UTC
Permalink
Post by Ivan
Abd: IAcabadoOLE(i);
Hard casting an interface like that is not safe, always us an 'as'
typecast.

From the symptoms you have described I would say that your server is
not implementing the COM object correctly.
--
Marc Rohloff [TeamB]
marc -at- marc rohloff -dot- com
Ivan
2008-07-30 14:41:52 UTC
Permalink
I have arranged
What I have done is rewrite the type library.
My theory is that the TLB created with the delphi 5 is not compatible
with the delphi 2007 (or at least for the types of data included in my
TLB).
Thanks.



On Mon, 28 Jul 2008 09:54:54 -0300, "Marc Rohloff [TeamB]"
Post by Marc Rohloff [TeamB]
Post by Ivan
Abd: IAcabadoOLE(i);
Hard casting an interface like that is not safe, always us an 'as'
typecast.
From the symptoms you have described I would say that your server is
not implementing the COM object correctly.
Loading...