delphi 8 for .net assemblies; packages and libraries
以下内容转自:http://www.drbob42.com/examines/examin55.htm
in this article, bob swart will explain what .net assemblies are, how we can use them in delphi 8 for .net applications, and especially how we can make them ourselves (it actually turns out that there is more than one way, and even some special way to use some of them in win32 applications).
dlls and .net assemblies
the world of windows application development introduced the dll - dynamic link library. a dll can contain a number of functions that can be called from an application that loads the dll (statically or dynamically). the windows api consists mainly of dlls. these dlls were written in c or c++, and came with a header file that described the interface of the dll. for pascal and delphi developers, it was not easy to use the dll if you didn't have a dll import unit. and back in 1989 i released headconv - my first c dll header converter, which is now available as free tool under management of the delphi-jedi darth project. the delphi jedi project itself was founded to produce delphi import units for c dll header files - a tedious job, but well appreciated by all delphi developers who ever needed to use a c dll header file.
why am i telling you this? because the world has changed. the .net framework is taking over the windows world, and the dll is being replaced by a new kind of library, called the .net assembly.
.net assemblies are more powerful than dlls in a number of ways. first of all, where a dll can only export functions (and not classes), the .net assembly can define classes that can be used and extended by other .net assemblies or applications. another significant benefit is the fact that the .net framework is language neutral. as a consequence, a .net assembly written in language x can be used by any language, including delphi 8 for .net. no more c dll header conversions ever!
add references
for a delphi 8 for .net application to use an assembly, all we need to do is add a reference to the assembly. and this is as easy as it sounds: you can either use the project | add reference dialog, or use the project manager and right-click on the project node and select add reference. in both cases, you get a dialog that will help you to select a specific .net assembly and add it to your project.
the same dialog can also be used to add references to com objects and activex to your project, using the com interop tab.
delphi 8 for .net assemblies
using delphi 8 for .net, we can create our own assemblies as well. however, at first you may wonder how to start, since the delphi 8 for .net object repository actually contains two different project types that will both result in a .net assembly: the library, and the package.
both solutions will work (although in general one is preferred over the other), but you may need a little additional information about their use and deployment specifics.
package or library?
let me tell you on beforehand that the recommendation from borland is to use a package when you're planning to write a .net assembly with delphi 8 for .net. however, because the delphi 8 for .net helpfiles contain information about packages and libraries, this isn't made very clear in the helpfile to be honest. and as a result, i've been using both a package and a library project to build my delphi 8 for .net assemblies, with mixed results. so just to let you know the inside store and to explain how and why, i'll use both ways and show the details.
library