Board index » delphi » Is it possible to obtain a reference to a managed component from unmanaged ToolsAPI?
Darin Dimitrov
![]() Delphi Developer |
Is it possible to obtain a reference to a managed component from unmanaged ToolsAPI?2005-05-27 07:10:47 PM delphi221 Hello, I have implemented a small wizard which needs to read the Fields property of a TADOQuery component placed on a form. I wrote the wizard using unmanaged ToolsAPI and used the IOTAFormEditor.FindComponent to obtain a reference to the desired component. Then I obtain an INTAComponent and cast it to TDataSet. Finally I obtain directly the Fields property of the component. Here is a code snippet: ...... var IOTADataSet: IOTAComponent; INTADataSet: INTAComponent; DataSet: TDataSet; Fields: TFields; ...... IOTADataSet := FormEditor.FindComponent('ADOQuery1'); if not Assigned(IOTADataSet) then Exit; if not Supports(IOTADataSet, INTAComponent, INTADataSet) then Exit; DataSet := TDataSet(INTADataSet.GetComponent); Fields := DataSet.Fields; ...... Everything works fine when I have an unmanaged project containing a form with the TADOQuery component. But when I try to do the same in a managed project the wizard doesn't work. It cannot obtain a reference to the INTAComponent. This behaviour didn't surprise me much because in my code the DataSet and Fields are unmanaged variables and I am trying to cast them to a managed component. So, is there some trick in order to make this work? Or I have to maintain 2 versions of the wizard (one using unmanaged ToolsAPI and other - the managed) - this would be a very BAD solution? I would greatly appreciate any suggestions. I forgot to mention that I am using Delphi 2005 with update 2 installed. Thanks, DARIN |