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
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
TclBlobField represents a field that holds a reference to a binary large object (BLOB - Binary Large Object) in the dataset.
TclBlobField represents a field that holds a reference to a binary large object (BLOB - Binary Large Object) in the dataset.<br>


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


BLOB fields allow for the storage of large binary data such as text, images, audio, or video.
BLOB fields allow for the storage of large binary data such as text, images, audio, or video.<br>


<div class="table-responsive">
{| class="wikitable" style="border: 2px solid #c3d7e0"
{| class="wikitable" style="border: 2px solid #c3d7e0"
! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"|Definition  
! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"| Definition  
|-
|-
|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.
|}
|}
</div>


'''Example:'''<br>


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).
<b>Example</b><br>


:'''TRObject Syntax'''
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).<br>


  var
<pre>
    Server, User, Password,DB: String;
var
    Port: Integer;
  Server, User, Password,DB: String;
    Form1:TCLForm;
  Port: Integer;
    qry : TClSqlQuery;
  Form1:TCLForm;
    BlobStream: TclMemoryStream;
  qry : TClSqlQuery;
    BlobField: TclBlobField;
  BlobStream: TclMemoryStream;
    Img1 : TclImage;
  BlobField: TclBlobField;
    Base64String: string;
  Img1 : TclImage;
 
  Base64String: string;
  void MainForm;  
  {
void MainForm;  
    Form1 = TCLForm.Create(Self);
{
    Img1 = Form1.AddNewImage(Form1,'Img1');
  Form1 = TCLForm.Create(Self);
    Img1.Align = alClient;
  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;
  }
    
    
  {
  qry = TClSqlQuery.Create(Nil);
    try
  try
      Server = '192.168.5.13';
    try  
      User = 'sa';
      qry.Connection = Clomosy.DBSQLServerConnection;
      Password = 'aaaa';
      qry.Sql.Text = 'SELECT TOP(1) DOC_FILE FROM ATBLDOCS';
      DB = 'ATK23';
      qry.Open;
      Port = 1433;
      if (qry.Found)
      Clomosy.EventLog = True;
      {
      if not (Clomosy.DBSQLServerConnect('SQL Server', Server, User, Password, DB, Port))
        BlobField = qry.FieldByName('DOC_FILE') as TclBlobField;
      {
        BlobStream = TclMemoryStream.Create;
        ShowMessage('DATABASE CONNECT ERROR');
        BlobField.SaveToStream(BlobStream); // Load BLOB data into the stream
        Exit;
        BlobStream.Position = 0;
      }
        Base64String = Clomosy.StreamToBase64(BlobStream);
      MainForm;
        Clomosy.setClipBoard(Base64String);//FOR TEST PURPOSE COPIES BASE64
    except
       
      ShowMessage('Connection Error '+'Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
        Img1.Bitmap.LoadFromStream(BlobStream); // Load the image from the stream
    }
        BlobStream.Free;
  }
      }
 
    except
:'''Base Syntax'''
      ShowMessage('[019] Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
 
    }
  var
  finally
    Server, User, Password,DB: String;
    qry.Free;
    Port: Integer;
  }
    Form1:TCLForm;
  Form1.Run;
    qry : TClSqlQuery;
}
    BlobStream: TclMemoryStream;
    BlobField: TclBlobField;
    Img1 : TclImage;
    Base64String: string;
    
    
  Procedure MainForm;
{
  begin
   try
    Form1 := TCLForm.Create(Self);
    Server = '192.168.5.13';
    Img1 := Form1.AddNewImage(Form1,'Img1');
    User = 'sa';
    Img1.Align := alClient;
    Password = 'aaaa';
   
    DB = 'ATK23';
    qry := TClSqlQuery.Create(Nil);
    Port = 1433;
    try
    Clomosy.EventLog = True;
      try
    if not (Clomosy.DBSQLServerConnect('SQL Server', Server, User, Password, DB, Port))
        qry.Connection := Clomosy.DBSQLServerConnection;
    {
        qry.Sql.Text := 'SELECT TOP(1) DOC_FILE FROM ATBLDOCS';
      ShowMessage('DATABASE CONNECT ERROR');
        qry.Open;
      Exit;
        if qry.Found then
    }
        begin
    MainForm;
          BlobField := qry.FieldByName('DOC_FILE') as TclBlobField;
  except
          BlobStream := TclMemoryStream.Create;
    ShowMessage('Connection Error '+'Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
          BlobField.SaveToStream(BlobStream); // Load BLOB data into the stream
  }
          BlobStream.Position := 0;
}
          Base64String := Clomosy.StreamToBase64(BlobStream);
</pre>
          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 ==


<h2> See Also </h2>
* [[Components]]
* [[TclFileStream]]
* [[TclFileStream]]
* [[TclMemoryStream]]
* [[TclMemoryStream]]
Line 157: Line 95:
* [[Base64ToFile]]
* [[Base64ToFile]]
* [[Base64ToStream]]
* [[Base64ToStream]]
{{#seo:|title=TclBlobField Using in Clomosy - Clomosy Docs}}
{{#seo:|description=Learn how to use TclBlobField in Clomosy to handle and manage BLOB data like images, audio, and video from a database, with practical examples.}}

Latest revision as of 15:05, 24 December 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).

 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);
   }
 }

See Also