Guide

# DBKit SDK

<div class="rst-class">

forsearch

</div>

DBKit SDK

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

The DBKit SDK is how you create your own controls that work with DBKit the way the built-in controls do. A control built with the SDK is bound to the data on a layout: DBKit keeps it filled with the current row's values, collects its changes when the row is saved, validates it along with the layout's other controls, and enables or disables it as the state of the row changes.

The SDK is a set of interfaces in the DBKit.SDK namespace. There is no SDK base class to subclass. Instead, you build your control from any Xojo control, or from a canvas if you are drawing it yourself, and implement the interface that matches what your control is for. DBKit finds the controls on a layout through these interfaces, so implementing one is all it takes for a control to become a DBKit control.

The Rating control in the DBKit example projects is a complete, working example of a custom control built with the SDK. Rating is a canvas that displays a value as a row of stars and lets the user change the value by clicking. It implements `DBKit.SDK.RowDataControl</api/databases/dbkit/sdk/rowdatacontrol>`.

## Choosing an interface

Which interface to implement depends on the control's relationship to the row, not on what the control looks like. A text field and a canvas can be the same kind of control in DBKit terms because both display and edit a single column.

| What the control does                                        | Interface to implement                                                          |
|--------------------------------------------------------------|---------------------------------------------------------------------------------|
| Displays and edits one column of the current row             | `DBKit.SDK.RowDataControl</api/databases/dbkit/sdk/rowdatacontrol>`             |
| Displays and edits an image column of the current row        | `DBKit.SDK.RowDataImageControl</api/databases/dbkit/sdk/rowdataimagecontrol>`   |
| Performs an action on the current row, such as New or Delete | `DBKit.SDK.RowActionControl</api/databases/dbkit/sdk/rowactioncontrol>`         |
| Is the button that starts and ends editing of the row        | `DBKit.SDK.RowActionEditControl</api/databases/dbkit/sdk/rowactioneditcontrol>` |
| Displays many rows at once                                   | `DBKit.SDK.RowsListControl</api/databases/dbkit/sdk/rowslistcontrol>`           |
| Only needs to react when things happen to the row            | `DBKit.SDK.RowEventReceiver</api/databases/dbkit/sdk/roweventreceiver>`         |

Layouts participate through an interface as well. The built-in layout classes, `DBKit.Window</api/databases/dbkit/window>`, `DBKit.Page</api/databases/dbkit/page>` and `DBKit.Container</api/databases/dbkit/container>`, implement `DBKit.SDK.Layout</api/databases/dbkit/sdk/layout>`. Your controls use that interface to talk back to the layout they are on.

## How DBKit works with your control

When a layout loads, DBKit collects the controls on it that implement the SDK interfaces and treats them as its own. From then on, the conversation runs in both directions.

When the current row changes, DBKit tells each data control to update itself from the row. When the row is about to be saved, DBKit asks each data control to write its value back into the row, after first checking the mandatory controls for valid values. As the row moves between viewing and editing, and between having changes and not, DBKit enables and disables the action controls so that each one is available only when its action makes sense.

Throughout the life of the row, DBKit also sends row events to the controls: the row was loaded, editing began, the row is about to be saved, and so on. A control reacts to the events it cares about and ignores the rest.

## The interfaces

### RowEventReceiver

`DBKit.SDK.RowEventReceiver</api/databases/dbkit/sdk/roweventreceiver>` is the root of the SDK. Every other control interface includes it, so every DBKit control receives row events. Its single method is called by DBKit whenever something happens to the row the control is associated with, and the control reacts to the events it cares about.

### RowEvent

A `DBKit.SDK.RowEvent</api/databases/dbkit/sdk/rowevent>` is the object passed to a control when something happens to a row. It says what happened, which row it happened to and which table that row belongs to. Its Type property is one of nine kinds of event, from the row being loaded to the row being saved or deleted.

### RowBase

`DBKit.SDK.RowBase</api/databases/dbkit/sdk/rowbase>` is included in every control interface. It gives DBKit the two things it needs to know about any control, whichever kind it is: the layout the control is on, and the name of the table the control's data comes from.

### RowDataControl

Implement `DBKit.SDK.RowDataControl</api/databases/dbkit/sdk/rowdatacontrol>` on a control that displays and edits one column of the current row. Most custom controls are of this kind. Through it, DBKit fills the control from the row, collects its value when the row is saved, and asks it whether it must have a value and whether its value is valid.

### RowDataImageControl

Implement `DBKit.SDK.RowDataImageControl</api/databases/dbkit/sdk/rowdataimagecontrol>` instead of RowDataControl when the column holds an image. It includes everything in RowDataControl and adds the two things DBKit needs to know in order to store the picture: the format to write it in and, for formats where quality applies such as JPEG, the quality to use.

The built-in `DBKit.ImageViewer</api/databases/dbkit/imageviewer>` is of this kind.

### RowActionControl

Implement `DBKit.SDK.RowActionControl</api/databases/dbkit/sdk/rowactioncontrol>` on a control that performs an action on the current row rather than displaying a column value, such as a button that creates, deletes or saves rows. An action control holds no data, so DBKit talks to it about state instead: it tells the control when the row enters or leaves edit mode, and enables or disables it according to the state of the row, so that each action is available only when it makes sense.

### RowActionEditControl

Implement `DBKit.SDK.RowActionEditControl</api/databases/dbkit/sdk/rowactioneditcontrol>` on the button that starts and ends editing of the row. It includes everything in RowActionControl and adds the button's caption, which DBKit sets as the state of the row changes, for example Edit when the row is not being edited and Done while it is.

### RowsListControl

Implement `DBKit.SDK.RowsListControl</api/databases/dbkit/sdk/rowslistcontrol>` on a control that displays many rows at once. This is the largest of the SDK interfaces, because the control takes over everything a list of rows involves: displaying the rows, selection, editing and relationships. `DBKit.Table</api/databases/dbkit/table>` is its implementation, and writing your own control of this kind is the advanced case; most developers never need to.

### Layout

`DBKit.SDK.Layout</api/databases/dbkit/sdk/layout>` is the interface a layout offers to the controls on it. The built-in layout classes implement it; a control never does. Your controls call its methods to work with the layout they belong to: its current row and the rows around it, its database, its other controls, and the schema questions a control sometimes needs to ask, such as whether a column name is valid for a table.

<div class="toctree" hidden="">

sdk/roweventreceiver sdk/rowbase sdk/rowdatacontrol sdk/rowdataimagecontrol sdk/rowactioncontrol sdk/rowactioneditcontrol sdk/rowslistcontrol sdk/layout sdk/rowevent

</div>

## Notes

The methods an interface requires can be implemented as Private, as the Rating example does. DBKit works with the control through the interface, so the methods do not need to be public on the control class itself.

The SDK is the same in the desktop and web versions of DBKit. The interfaces are identical, so the SDK code in a control does not change between platforms; only the control's own drawing and interaction code differs, as it would for any Xojo control.

## Compatibility

|                       |              |
|-----------------------|--------------|
| **Project Types**     | Desktop, Web |
| **Operating Systems** | All          |
