Invalid class typecast error in a dll
Posted: Fri 09 Dec 2011 11:45
Hi guys!
I made a test application:
Dll code:
and the caller code:
what is the wrong?

I made a test application:
Dll code:
Code: Select all
library dlltest;
uses
SysUtils,
Classes,
MyAccess;
procedure Test(MyConnection: TMyConnection); cdecl; export;
var q: TMyQuery;
begin
try
q:=TMyQuery.Create(nil);
q.Connection:=MyConnection;
q.SQL.Text:='select version() as ver';
q.Open; // <--- Here is the error: Invalid class typecast
q.Close;
except
end;
FreeAndNil(q);
end;
exports
Test;
begin
end.
Code: Select all
program dllcaller;
{$APPTYPE CONSOLE}
uses
MyAccess;
procedure Test(MyConnection: TMyConnection); cdecl; external 'dlltest.dll' name 'Test';
var conn: TMyConnection;
begin
try
conn:=TMyConnection.Create(nil);
conn.Server:='localhost';
conn.Database:='mysql';
conn.Port:=3306;
conn.Username:='root';
conn.Password:='root';
conn.LoginPrompt:=False;
conn.Open;
Test(conn);
conn.Close;
except
end;
end.