From Clomosy Docs
TclBlobField represents a field that holds a reference to a binary large object (BLOB - Binary Large Object) in the dataset.
TclBlobField encapsulates the basic behavior common to binary large object (BLOB - Binary Large Object) fields. BLOB fields are database fields that contain raw binary data of arbitrary length. BLOB fields can represent different, optionally large data types. These data types are distinguished in the header of the binary data.
BLOB fields allow for the storage of large binary data such as text, images, audio, or video.
| Feature | Use of | Definition |
|---|---|---|
| TclBlobField | BlobField : TclBlobField; | A variable belonging to the TclBlobField class is created. |
| Assigning to object | BlobField = qry.FieldByName('DOCUMENT_FILE') as TclBlobField; | Assigning to a TclBlobField object |
| SaveToStream | BlobField.SaveToStream(BlobStream); | Saves BLOB data to a TclMemoryStream or TclFileStream object. |
Example
This code connects to a SQL Server database, executes a query on a table, and loads image data from a BLOB (Binary Large Object) field. It saves the loaded image data into a stream (TclMemoryStream), then loads this data into a visual component (TclImage) and displays it. Additionally, it copies the image data in Base64 format to the clipboard (setClipBoard).
var
Server, User, Password,DB: String;
Port: Integer;
Form1:TCLForm;
qry : TClSqlQuery;
BlobStream: TclMemoryStream;
BlobField: TclBlobField;
Img1 : TclImage;
Base64String: string;
void MainForm;
{
Form1 = TCLForm.Create(Self);
Img1 = Form1.AddNewImage(Form1,'Img1');
Img1.Align = alClient;
qry = TClSqlQuery.Create(Nil);
try
try
qry.Connection = Clomosy.DBSQLServerConnection;
qry.Sql.Text = 'SELECT TOP(1) DOC_FILE FROM ATBLDOCS';
qry.Open;
if (qry.Found)
{
BlobField = qry.FieldByName('DOC_FILE') as TclBlobField;
BlobStream = TclMemoryStream.Create;
BlobField.SaveToStream(BlobStream); // Load BLOB data into the stream
BlobStream.Position = 0;
Base64String = Clomosy.StreamToBase64(BlobStream);
Clomosy.setClipBoard(Base64String);//FOR TEST PURPOSE COPIES BASE64
Img1.Bitmap.LoadFromStream(BlobStream); // Load the image from the stream
BlobStream.Free;
}
except
ShowMessage('[019] Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
}
finally
qry.Free;
}
Form1.Run;
}
{
try
Server = '192.168.5.13';
User = 'sa';
Password = 'aaaa';
DB = 'ATK23';
Port = 1433;
Clomosy.EventLog = True;
if not (Clomosy.DBSQLServerConnect('SQL Server', Server, User, Password, DB, Port))
{
ShowMessage('DATABASE CONNECT ERROR');
Exit;
}
MainForm;
except
ShowMessage('Connection Error '+'Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
}
}