In this article:

General Information

Read and Write Custom and Binary Fields

Set Field Value

Read Field Value

Example

Working with Fields That Have Custom Data Type

Article number: KB000031

General Information

When working with the repository table, on creating new fields the user should specify the data type to be stored in this field. In addition to basic types (String, Integer, Double, Date), one of the custom data types can be specified: Custom, Text or Binary. A certain type of field is created in the physical table on the server, to which this repository table corresponds. The following are the types of physical tables fields depending on user's DBMS:

Type of the field in the repository table Oracle Microsoft SQL Server DB2
Custom LONG RAW VARBINARY(MAX) BLOB
Text CLOB (NCLOB when working with Unicode) VARCHAR(MAX) (NVARCHAR(MAX) on working in Unicode) CLOB (NCLOB when working with Unicode)
Binary BLOB VARBINARY(MAX) BLOB

To get supported DBMS version, see theSupported DBMS section.

Text fields are used to store character information. The values of such fields are specified as any character data, which length does not exceed the limit set for this type of data.

Custom and binary fields are used to store binary data. Streams are used to work with this data type, as described below.

Read and Write Custom and Binary Fields

Custom and binary fields take reference to a stream that contains any data as their value. The stream may be associated with any file or created dynamically in memory. Repository objects that support saving to the stream can also be stored in custom fields. After transaction, stream data is recorded in the repository database. Custom and binary field values are also retrieved in the stream. For this purpose a static method is used FromVariant of the class IOStream. Data loaded in the stream can be edited and resaved later.

Set Field Value

Var
    //...
    Fields: IDatasetInstanceFields;
    StreamData: IIOStream;
    //...
Begin
    //...
    Fields.FindById("<Field ID>").Value := StreamData;
    //...

Read Field Value

Var
    //...
    Fields: IDatasetInstanceFields;
    StreamData: IIOStream;
    //...
Begin
    //...
    StreamData := IOStream.FromVariant(Fields.FindById("<Field ID>").Value);
    //...

Example

Consider an example of writing and reading data in a binary field. To execute this example, create a table with the TImages identifier with the following fields:

Field identifier Field type Brief Description
IMG_NAME Text File name.
IMG Binary An image file.

Also create a form as an example. The following components are placed on the form:

When the form is loaded, the table opens and cache entries are obtained. Clicking the BPrior and BNext buttons allows navigating the cache entries. Any move in the cache invokes the LoadRecord procedure. This procedure retrieves values of current entry fields. Image from the IMG field is loaded in the stream, the content of which is loaded in the ImgBox component. Clicking the BAdd button displays the file selection dialog box. After selecting an image file, a new entry is added. File name and the file itself are recorded in the table. The Fore.NET example uses the ForeIOStreamMarshaler class that allows casting the IIOStream Fore type to the System.IO.Stream .NET type, which is needed for loading the image in the PictureBox component.

Fore example

Fore.NET example

To store a repository object in the IMG field, for example a regular report, transform the code above and add the following components to the form:

Fore example

Fore.NET example

See also:

Developers Knowledge Base