Invalid type cast in DLL repeat in version 5.70

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
alex D
Posts: 3
Joined: Fri 24 Jul 2009 09:02

Invalid type cast in DLL repeat in version 5.70

Post by alex D » Fri 24 Jul 2009 09:30

Hello!
I use your VCL component MyDac from DLL (С++). Both Application and dll use borlndmm.dll for memory managment and dynamic standart RTL lib. After update IDE from RAD Studio 2007 to version RAD Studio2009 appear problem:
some simple request to mysql like 'select name from mytable;' throw exception EInvalidCast on call TMyQuery::Execute.
Table description `mytable`:
is InnoDB engine;
contain fields `id` - integer (primary key) and `name` - char(32);
use cp1251 (Russian charset).

In revision history you write:
5.50.0.35 11-Jun-08
* Fixed bug with 'Invalid class typecast' error inside dlls.
May be problem not fixed in version 5.70?
Also problem appear in Trial version 5.80.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 27 Jul 2009 09:19

Please try to compose a small sample to demonstrate the problem and send it to dmitryg*devart*com.

alex D
Posts: 3
Joined: Fri 24 Jul 2009 09:02

Post by alex D » Thu 30 Jul 2009 08:28

I sent sample to email

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 30 Jul 2009 08:42

Thank you for information. We are investigating this problem. As soon as we solve the problem we will let you know.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 30 Jul 2009 09:16

This problem is connected with work with dll. The point is that you create the TMyConnection class object in an application and use it with the TMyQuery object, created in dll. These methods use the "as" operator which returns invalid type cast error.
To solve this problem you should create TMyConnection object in dll.

alex D
Posts: 3
Joined: Fri 24 Jul 2009 09:02

Post by alex D » Thu 30 Jul 2009 15:27

Ok. I understand - RTTI mechanism is different for application and dll. That bug appear only with linking static MyDAC libs.
I solve the problem by use bpl dynamic linking.
Thanks for information!

Gigasoft
Posts: 13
Joined: Fri 14 May 2010 06:32

Post by Gigasoft » Fri 21 May 2010 04:45

Dimon wrote:This problem is connected with work with dll. The point is that you create the TMyConnection class object in an application and use it with the TMyQuery object, created in dll. These methods use the "as" operator which returns invalid type cast error.
To solve this problem you should create TMyConnection object in dll.
Sorry to dig up an old thread, but I've just run into this problem myself.
The interesting thing is that it seems to have randomly cropped up. Until today this method (TMyConnection in App, Table/Query components in dll) has been working perfectly - in fact in all but one dll module it is still working.
Can you explain why it might have suddenly stopped working?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Fri 21 May 2010 06:45

To solve the problem try to use the TCustomMyConnection.AssignConnect method to assign the TMyConnection object created in dll to the TMyConnection object of application.
Also you can use the approach used in the MyDAC DLL demo.

Gigasoft
Posts: 13
Joined: Fri 14 May 2010 06:32

Post by Gigasoft » Mon 24 May 2010 03:48

Thanks, AssignConnect works nicely, but doesn't allow me to do application wide monitoring using a TMySQLMonitor.

I've solved the problem by adding MyDAC70 and DAC70 to the runtime packages list - I actually thought I'd already done this, but apparently not.

Post Reply