Page 1 of 1

Invalid class typecast

Posted: Fri 26 Aug 2011 21:22
by luis_augusto
I´ve upgraded from sdac 2.79 to unidac 3.5 and, since then, I am having trouble with the following:


field1 = varchar(15)
field2 = text
field3 = text

when I try to do this, after opening the Tuniquery:

begin
Uniquery1.sql.text:='Select field1,field2,field3 from tablea'

tt:=tstringlist.create;
uniquery1.open;

tt.settext(pchar(Uniquery1.fieldbyname('field2').asstring)); <=== Error 'Invalid class typecast'
Uniquery1.close;
end;

I am using MSSQL 2008 and Unidac 3.70.0.19 for Delphi7
This routine is inside a dll

Posted: Tue 30 Aug 2011 11:00
by AndreyZ
Hello,

I cannot reproduce the problem. Please try creating a small sample to demonstrate the problem and send it to andreyz*devart*com.

workaround to "invalid class typecast"

Posted: Tue 30 Aug 2011 13:10
by luis_augusto
Hello,

It seems the fact that the routine is inside a dll is critical to raise this exception.

I substitute Query.fieldbyname('fieldname').asstring for tmemdataset(Query).getblob('fieldname').asstring, then the problem was solved.
Nevertheless, in a system with a huge amount of code,this problem can turn the program into a "mined field", since one would have to find every dll where this technique was used to change it.
your customer´s the legacy, when changing the behaviour of your code. Mainly, because people who is interested in a kind of software like yours is also interested in the preservation of its own legacy.

That been said, Unidac rocks!

Posted: Wed 31 Aug 2011 11:54
by AndreyZ
I used your code in a dll, and there were no problems. We are interested in investigating this problem. Please try composing a small sample to demonstrate the problem and send it to andreyz*devart*com, including a script to create and fill the tablea table. We are looking forward to receiving your sample.

Sample sent

Posted: Wed 31 Aug 2011 15:39
by luis_augusto
I sent you a sample. It appears to be related with the origin of the connection. If the connection is created inside the dll there is no problem, but if you use a TUniconnection as a parameter for the external procedure and use it to open a TUNIquery inside the dll, the exception raises.

Posted: Thu 01 Sep 2011 07:10
by AndreyZ
You are right, this problem is caused by using a connection that was created in an application inside dll. In this case the "as" operator is used that causes invalid type cast error. To solve the problem, you can use one of the following ways:
- create and configure TUniConnection inside dll;
- create TUniConnection inside dll and use the AssignConnect method to share database connection. I've sent you your sample with my corrections. It demonstrates this approach.

Posted: Thu 01 Sep 2011 13:35
by luis_augusto
yes, this solution works fine for me. Thanks a lot.