Accessing a COM component
The third tutorial describes how to access a COM component and build
reusable library.
Step by step instructions
-
Launch the wizard
-
Choose Create a new project from a COM definition and click Next
-
Click Next again
-
Click the top Browse button and open the file $ISE_EIFFEL\examples\com\wizard\string_manipulator\string_manipulator.idl
where $ISE_EIFFEL represents the path to your EIFFEL50 directory. You could also choose to open the type library (.tlb) that was generated by the wizard when
Creating a new COM component.
in the destination folder of that first project.
-
Click the bottom Browse button and select the directory where you want to create the project (later referenced as destination folder). Choose
$ISE_EIFFEL\examples\com\wizard\string_manipulator\client\generated where $ISE_EIFFEL represents the path to your EIFFEL50 directory.
-
Click Next
-
Click Finish
-
Wait until the wizard is done.
First look at the generated code
At the and of the generation the
wizard precompiles the generated code and open EiffelStudio on the
precompilation project. Note: a precompilation project is read-only, you need
to start another EiffelStudio to reuse the generated classes. The interesting
classes are all related to the coclass proxy
STRING_MANIPULATOR_PROXY. The
proxy is the Eiffel class that gives access to the component. Each feature on
the proxy calls the corresponding interface function on the component. You can
use the EiffelStudio opened by the wizard to browse through the generated
classes and study the class hierarchy.
Implementing a client
To implement a client of the StringManipulator component open a new
EiffelStudio. Create the project in
$ISE_EIFFEL\examples\com\wizard\string_manipulator\client
using the ace file found in that directory. Freeze and run the project. You are
now accessing the previously built component and calling functions on its
interfaces!. The class
MY_STRING_MANIPULATOR inherits from the
generated
STRING_MANIPULATOR_PROXY and redefines the feature
replace_substring_user_precondition.
The generated interfaces include contracts for each exposed function. You can
redefine the
user_precondition features to implement your own
preconditions.
Contracts
Contracts can be broken directly on the proxy in which case you will get a standard contract violation or in the server. If contracts are broken on the server then the exception will be forwarded by the EiffelCOM runtime to the client. The feature replace_substring_user_precondition in
MY_STRING_MANIPULATOR
includes the following commented line:
Un-comment this line by removing the preceding `
' and comment out the rest of the feature. Now the contract of the
replace_substring
feature is wrong and erroneous calls can be made. Quick melt the changes and run the client. Enter some invalid numbers in the fields used to call this feature. After you click Replace you will see an error message box warning you that a precondition was violated on the server side. This is how you can use contracts `over the wire'. The preconditions was violated in the server, this exception was caught by the EiffelCOM runtime and sent back to the client.
See Also: Creating a new COM component,
Creating a new component from an
Eiffel Project.