Invalid class typecast inside DLL (5.80.0.47)
Posted: Thu 22 Jul 2010 04:52
Hello !.
I have problem.
From main application, I try share connection to DB with my DLL.
DLL correctly shows database, username, password, server, but if I open Query then is throwing exception
if, Instead of TMyConnection, I put TMyQuery as result of "GetConnection" and directly use, then is OK...
I have problem.
From main application, I try share connection to DB with my DLL.
DLL correctly shows database, username, password, server, but if I open Query then is throwing exception
if, Instead of TMyConnection, I put TMyQuery as result of "GetConnection" and directly use, then is OK...
Code: Select all
library Project1;
uses
MyAccess, Dialogs;
{$R *.res}
type
ILabReport = interface
['{868368F0-42D9-404E-960A-EF3EEFFE87CF}']
procedure CreateReport(const Path: PChar);
end;
ILabProgram = interface
['{B3E9CEF9-E3FF-4A77-A61E-3B8942BF7D41}']
function GetConnection: TMyConnection;
end;
TLabReport = class(TInterfacedObject, ILabReport)
private
Q: TMyQuery;
public
constructor New;
procedure CreateReport(const Path: PWideChar);
end;
var
LabReport: ILabReport;
LabProgram: ILabProgram;
procedure TLabReport.CreateReport(const Path: PWideChar);
begin
Q.Connection := LabProgram.GetConnection;
Q.SQL.Text := 'SELECT xx from xxxx';
Q.Open;
showmessage(Q.Fields[0].AsString);
Q.Close;
end;
constructor TLabReport.New;
begin
Q := TMyQuery.Create(nil);
end;
procedure Connect(const LabProg: ILabProgram; out LabRep: ILabReport);
begin
LabProgram := LabProg;
LabReport := TLabReport.New;
LabRep := LabReport;
end;
procedure Disconnect;
begin
LabReport := nil;
LabProgram := nil;
end;
exports
Connect, Disconnect;
begin
end.