
NOTE: This tutorial requires Delphi 4 or higher since it uses toolbar controls.

This is a short "how to" on using the native set of components within IB Objects. This set is not the replacement components for the bde. If you want to port an existing application to IBO, this "how to" is not specifically for you, there are easier components you can use.

In addition to introducing the native components, I will try to establish a "test bench" approach so you can play with the components and extend your knowledge of them.

First off, I assume you've already installed the components within Delphi.

Start a new Delphi application. We will put everything on one form for simplicity. Don't change the default names until you are comfortable flying solo.

We will be adding components to the form. Start with a tool bar, it is on the Win32 tab. Right click on the tool bar, add two buttons. We will use these buttons during execution to open and close things.

We are going to drop an TIB_Monitor onto the form and watch the sql traffic between the program and interbase. This is not necessary (until you try to develop a real application). We need two things. First drop a Delphi memo control on the form to receive and show the traffic. Set its properties as follows:

alignment -> Top
scrollBars -> ssBoth

Then drop a TIB_Monitor control - it is on the IB TOOLS tab, the last component. Go to Object Inspector, the events tab, and double click on OnMonitorOutput. Add this line of code to the TForm1.IB_Monitor1MonitorOutPutItem (assuming you've kept the default names for components):

  memo1.Lines.add (newString);
	
Now drop a TIB_Connection component on the form from the IB Access tab. It is currently the second component - IB_Connection. Note, there is a TIB_Database component, it looks like the bde TDatabase component. Do not use it. It works fine, but it limits what you can do to the bde approach (one connection = one transaction). 

Returning to the TIB_Connection. Look at the properties in the Object Inspector. Don't panic. Only set the following parameters (reading from top to bottom):

1) Password -> masterkey (or yours)
2) Path -> C:\program Files\Borland\Delphi 3\Demos\Data\employee.gdb (or where the data is on your system)
3) Protocol -> cpLocal  (very, very important - use cpTCP_IP or cpNETBEUI if your data is on a server)
4) Server -> (nothing if local (on your workstation) or the server name if remote)
5) Username -> SYSDBA (or as appropriate to your environment)

Now test it - double click on the Connected property to set it to true. If all is correct, you will have a connection to the database. If not, check to be sure interbase is running, your username and password are valid, the protocol is appropriate, the path is proper from interbase's perspective. Leave the component connected; don't do this in a production program - connect it when appropriate during execution (we will use the buttons we added above). If you are familiar with the IB_WISQL tool then double-click on the TIB_Connection component and use the form to enter the property values.

Now we will place a transaction component. You have three choices. A transaction component for one connection, IB_TransactionSingle, it has a "1" to the lower right. This is probably the one you will want, and the one we will use. You don't need to finish this paragraph, it describes the other two choices. There is a transaction component for two connections, IB_TransactionDouble, a "2" to the lower right. This is probably the component you will use when changes must happen in two databases. It makes two phase commit a breeze for a Delphi programmer. The last choice is a IB_TransactionMultiple - it generalizes the two phase commit to one or more databases.

Set the following IB_TransactionSingle properties:

1) IB_Connection -> IB_Connection1 (or whatever you named the connection component).

If we wanted do, we could add another transaction component and use the same TIB_Connection. This simple example doesn't need more than one transaction context.

Now that we have a connection and a transaction we have to choose the component to change data, change the structure of the database, run a procedure in the database, run a query, etc. The choice of component is a major decision - choose the wrong one and it may not be a fruitful experience. Because we are going to retrieve multiple rows of data with a select statement we only have two choices - a cursor or a query. We will first pick the IB_Cursor, the component with a large arrow pointing to the right, We are going to pick this for several reasons:

1) it offers the most choice
2) it is "stranger" for a bde based programmer.

Look at the properties in the object inspector. Don't panic.

Set the TIB_Cursor properties as follows:

1) IB_Connection -> IB_Connection1 (or whatever)
2) IB_Transaction -> IB_TransactionSingle1 (or whatever)
3) SQL -> Select * from employee (no semi colon and obviously this is not a production query)

Double click Active - it should become true. If not make sure your connection is active, things were spelled correctly, etc.

We are nearly done. Drop a TIB_DataSource on the form, the last component on this tab. Set its properties as:

1) DataSet -> IB_Cursor1 (or whatever)

You should notice that enabled became true.

Drop a splitter on the form. It is on the Additional tab, the vertical line with a double ended arrow. 

1) Align -> alTop

Lastly, drop a TIB_CursorGrid on the form - this is on the IB Controls tab. It is the second grid, the one with the letter C on it.

1) Align -> alClient
2) DataSource -> IB_DataSource1 (or whatever)

Surprised? The grid shows the column names, but no data. That's OK. This can be very frustrating for a BDE oriented programmer. 

For now, click on the TIB_Cursor on your form. Set the following properties:

1) AutoFetchAll -> True
2) Active -> True (it may have been reset)

You should see the grid filled in. If not, set the TIB_Cursor active to false then true. You should see the grid fill in.

Now let's set some execution code (a programmer does have to write code).
Double click on the first button on the tool bar. Add these lines of code to TForm1.ToolButton1Click:

  memo1.lines.Clear;
  ib_Monitor1.Enabled := True;
  ib_connection1.connect;
  ib_Cursor1.Open;

Double click on the second button and add these lines of code to TForm1.ToolButton2Click:

  ib_Cursor1.Close;
  ib_Connection1.Disconnect;
  ib_Monitor1.enabled := False;

Last part, select the form in the object inspector. Go to the events tab, double click on OnCloseQuery, add the following lines:

  ToolButton2Click (Sender);
  canClose := True;

Run the program.

Back at the ide, select the ib_Monitor1, double click on monitorGroups, set everything to True. Do the same for StatementGroups. Run the program again, look at the traffic.

You can run the program to verify all works. But it doesn't do much yet.

Let us play a little more before we go into depth. 