An overview
-------------

This is a revised version of the MTS distributed transaction
example described in our (Sergey Trepalin's and my) book 
devoted to Delphi 4 & COM.

This example was tested on Windows NT Workstation SP4 
(Russian) & MTS 2.0.

In this version: 
- the mistakes found were corrected;
- the mistakes missed were kept;
- some new mistakes were possibly added.

You can use this example without any restrictions. But
if it is used as a part of a book or an article, I would
be glad to be referred to.


The subject area of this example
---------------------------------

This example is a simple simulation of an ordering goods
from a stock. 

The Interbase table in the st2.gdb contains a list of items
available in a stock (their number, name and price). The first 
server object, st.dll, is to manage adding and deleting recors of
this table. The third field of this table is its primary key.
The appropriate trigger and generator are used to set its value.

The Paradox table delivery.db is a list of instructions, what
is to be delivered, and where it is to be delivered. The target 
address is a result of the user input in a client 
application. The dels.dll is to manage this table (we can suppose
that some operations with this table can be also made by an old 
Paradox application).

The dBase table ord.dbf is a list of invoices, which are sent to
the specified addresses (they are the same as the delivery
addresses). We can  suppose that some operations with 
this table can be also made by an old Clipper application.

The paysrv.dll is to:
- manage this table;
- manage distributed transaction, which is used to create an 
  order to deliver a selected item from the stock list to 
  an address specified by the user, and to create an invoice, 
  which is to be sent to the same address.

This distributed transaction consists of:
- deleting a record from the stock Interbase table;
- adding a new record to the delivery.db; this record contains an 
  address specified by the user, the name of an item from the 
  deleted Interbase record, and the primary key of the deleted 
  record;
- adding a new record to the ord.dbf; this record contains the same
  address, the price of an item from the deleted Interbase record,
  and the primary key of the deleted record;

Note:  it better to open the MMC, select the MTS package created,
then select the Properties option from the pop-up menu,  open the
Advanced tab, and set Shut down after being idle property to zero.
It prevents the server objects from staying in memory, when they
are not already required by its clients.

This example also contains two client aplications. 

The first is the stcl.exe. It is a test of the st.dll.
To add a new item to the stock table, you can fill the fields 
below and click the "Add..." button. To delete an item, you can
select a row in a grid and click the "Delete..." button.

The second is the pallcl.exe application. It is used to initiate
distributed transaction. To use it, you can select a row in the  
grid of the "Stock data" tab, input  the customer address and click 
the "Process" buton. This record will be deleted, and the 
appropriate records in the grids of  the "Stock and delivery data" 
tab must appear.

If something goes wrong during executing the client applications,
you can stop MTS DTC or server processes using MMC. 

If you run two instances of pallcl.exe, you can try to order the same
item by two different customers, and then observe the distributed 
transaction rollback. 


How to install this example
----------------------------

1.Unzip all contents of this archive to the c:\d4exams directory, or
 place all content of the \Data subdirectory just to the 
 C:\d4exams\MTS\Data directory (the fixed path is used here instead 
 of creating 3 aliases). 

2.Open the mts_pg1.bpg file in the Delphi 4 IDE and build all projects.

3.Install all DLLs (st.dll,  dels.dll, paysrv.dll) into the same 
  MTS package.

  Don't register all servers by 'Register ActiveX server'! (Only
  by 'Install MTS object'). Be sure that the BDE-MTS package is
  correctly installed in your MTS environment.


I hope this example could be useful.

You can criticize me using the following e-mail address: 
1011.g23@relcom.ru .


With best regards,
Natalia Elmanova

http://www.geocities.com/SiliconValley/Way/9281




