The act of adding a reference to a type library to a Delphi for .NET project (usually) causes the IDE to generate an Interop Assembly using the type library importing support in the .NET Framework. If you were using the command-line compiler, you would need to perform this step yourself, as discussed next.
The SAPI 5.x type library is linked into the in-proc COM server sapi.dll, but the type library specifies that the library name is actually SpeechLib. This can be verified by opening the file that contains the type library into Delphi for .NET; the library name shows as the top-level node in the type library hierarchy, as shown in Figure 16.3.
COM servers created with Win32 versions of Delphi and C++Builder default to using the project name as the library name, so there is less confusion between the COM server name and the Interop Assembly name.
This library name is used as the basis of the Interop Assembly name and internal namespace. Convention dictates that Interop Assemblies are prefixed with Interop and a period, making the SAPI 5.x Interop Assembly called interop.SpeechLib.dll containing items within a namespace of SpeechLib.
The IDE creates Interop Assemblies in a subdirectory of your project directory named Comlmports. When the application is launched, the Interop Assembly would not normally be found in this location. (It isn't installed in the Global Assembly Cache and is not in a directory that would be found through probing the application base or culture directories.) Because of this, the reference to the Interop Assembly in the Project Manager has its Copy Local option set on its context menu, as shown in Figure 16.4, as well as displayed on the Object Inspector (see Figure 16.2).
FIGURE 16.4 Interop Assemblies use the Copy Local option.
The Copy Local option means that the Interop Assembly will be copied into the project's output directory to ensure that it compiles when run on the development machine. However, consideration still needs to be given to what happens on machines the application is deployed to. You can deploy the Interop Assembly in the same directory as the application (or in a directory that will be found by probing), or you can install it in the Global Assembly Cache. Alternatively, you can set up an application configuration file that tells .NET where to find the assembly. A final option involves specifying a Primary Interop Assembly for the COM server, as we shall see a little later.
Was this article helpful?
What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.