"Invalid class typecast" error with DLL's TMSQuery.Post
Posted: Sat 04 Feb 2012 13:38
"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;
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;