From Clomosy Docs

(Created page with "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 f...")
 
No edit summary
Line 10: Line 10:
|TclBlobField|| BlobField : TclBlobField;  || A variable belonging to the TclBlobField class is created.
|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 TBlobField object
|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.
|SaveToStream ||BlobField.SaveToStream(BlobStream); || Saves BLOB data to a TclMemoryStream or TclFileStream object.

Revision as of 12:18, 5 June 2024

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).

TRObject Syntax
 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);
   }
 }
Base Syntax
 var
   Server, User, Password,DB: String;
   Port: Integer;
   Form1:TCLForm;
   qry : TClSqlQuery;
   BlobStream: TclMemoryStream;
   BlobField: TclBlobField;
   Img1 : TclImage;
   Base64String: string;
 
 Procedure MainForm; 
 begin
   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 then
       begin
         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;
       end;
     except
       ShowMessage('[019] Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
     end;
   finally
     qry.Free;
   end;
   Form1.Run;
 end;
  
 begin
   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) then
     begin
       ShowMessage('DATABASE CONNECT ERROR');
       Exit;
     end;
     MainForm;
   except
     ShowMessage('Connection Error '+'Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
   end;
 end;


See Also