"Invalid class typecast" error calling TMSQuery.Post method of dynamically created TMSQuery in a dll.
Steps to reproduce:
1) Use included demo app {InstallDemosDir}\Demos\Miscellaneous\Dll
2) Modify procedure ShowForm in DLLMain unit:
procedure ShowForm; cdecl;
var
msq: TMSQuery;
begin
with TfmDllMain.Create(Application) do
begin
msq := TMSQuery.Create(nil);
msq.Connection := ExternalMSConnection;
//put proper SQL statements
msq.SQL.Text := 'SELECT * FROM some_table';
msq.SQLInsert.Text := 'INSERT INTO some_table...';
msq.SQLUpdate.Text := 'UPDATE some_table...';
msq.Open;
msq.Append;
msq.FieldByName('some_field').AsInteger := 0;
msq.Post; <<- invalid typecast error occurs
msq.Free;
Inc(FormCount);
Caption := IntToStr(FormCount) + '. ' + Caption;
MSQuery.Connection := ExternalMSConnection;
MSQuery.Active := True;
Show;
end;
end;
"Invalid class typecast" error with DLL's TMSQuery.Post
-
AndreyZ
Hello,
Thank you for the information. We have reproduced and fixed this problem. This fix will be included in the next SDAC build.
To solve the problem, you should replace the code:with the following code:Also, you should add the following code to the finalization section:
Thank you for the information. We have reproduced and fixed this problem. This fix will be included in the next SDAC build.
To solve the problem, you should replace the code:
Code: Select all
procedure AssignConnection(MSConnection: TMSConnection); cdecl;
begin
ExternalMSConnection := MSConnection;
end;Code: Select all
procedure AssignConnection(MSConnection: TMSConnection); cdecl;
begin
if ExternalMSConnection = nil then
ExternalMSConnection := TMSConnection.Create(nil);
ExternalMSConnection.AssignConnect(MSConnection);
end;Code: Select all
ExternalMSConnection.Free;