.NET Zip component, Delphi Zip component, Barcode .NET, BDE Replacement and other .NET and Delphi components from ComponentAce
Products Download Order Contact us

Search
 

Delphi/C++ Components
.NET Components
ActiveX Controls
Kylix Components

Download

Download
Download Commercial
Trial Limitations

Support

Submit Request
Support Options

Order

Purchase
Competitive Upgrade
Premium Support
Sales Policy
Upgrade Policy
License Types

Info

News
Mailing List
Articles
Testimonials



About Us
Partners
Links
Contact Us
Link to Us





Home > Delphi/C++ Components > Absolute Database > Blob Jpeg Field Delphi Example

Absolute Database

Overview | Features | Requirements | Testimonials | SQL Samples | Code Samples | Screenshots | See Also | Download | Order
Blob Jpeg Field Delphi Example
Shows how to store and display JPEG image in BLOB field.

Download Absolute Database | Learn more

unit Main;

interface
{$I CompVer.inc}

uses
{$IFDEF D6H}
  Variants,
{$ENDIF}
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, DB, ABSMain, Jpeg;

const
  DataBaseFileName: String = '..\..\Data\Demos.abs';

type
  TfrmMain = class(TForm)
    GroupBox1: TGroupBox;
    Label3: TLabel;
    dbDemos: TABSDatabase;
    tPhotoAlbum: TABSTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    btSaveImage: TButton;
    odBlob: TOpenDialog;
    sdBlob: TSaveDialog;
    btLoadImage: TButton;
    GroupBox2: TGroupBox;
    Photo: TImage;
    procedure FormCreate(Sender: TObject);
    procedure btLoadImageClick(Sender: TObject);
    procedure btSaveImageClick(Sender: TObject);
    procedure tPhotoAlbumAfterScroll(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

{$R *.dfm}

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  dbDemos.DatabaseFileName := ExtractFilePath(Application.ExeName) + DataBaseFileName;
  dbDemos.Open;
  tPhotoAlbum.Open;
end;

procedure TfrmMain.btLoadImageClick(Sender: TObject);
var
  FileStream: TFileStream;
  BlobStream: TStream;
begin
 if (odBlob.Execute) then
   begin
     tPhotoAlbum.Edit;
     try
       BlobStream := tPhotoAlbum.CreateBlobStream(tPhotoAlbum.FieldByName('Photo'),bmWrite);
       FileStream := TFileStream.Create(odBlob.FileName,fmOpenRead or fmShareDenyNone);
       BlobStream.CopyFrom(FileStream,FileStream.Size);
       FileStream.Free;
       BlobStream.Free;
       tPhotoAlbum.Post;
       tPhotoAlbumAfterScroll(tPhotoAlbum);
     except
       tPhotoAlbum.Cancel;
     end;
   end;
end;

procedure TfrmMain.btSaveImageClick(Sender: TObject);
var
  FileStream: TFileStream;
  BlobStream: TStream;
begin
  if (sdBlob.Execute) then
    begin
      FileStream := TFileStream.Create(sdBlob.FileName,fmCreate);
      BlobStream := tPhotoAlbum.CreateBlobStream(tPhotoAlbum.FieldByName('Photo'),bmRead);
      FileStream.CopyFrom(BlobStream,BlobStream.Size-BlobStream.Position);
      BlobStream.Free;
      FileStream.Free;
    end;
end;

procedure TfrmMain.tPhotoAlbumAfterScroll(DataSet: TDataSet);
var
  JpegImage: TJPEGImage;
  BlobStream: TStream;
begin
  if (not tPhotoAlbum.FieldByName('Photo').IsNull) then
    begin
      BlobStream := tPhotoAlbum.CreateBlobStream(tPhotoAlbum.FieldByName('Photo'),bmRead);
      JpegImage := TJPEGImage.Create;
      try
        JpegImage.LoadFromStream(BlobStream);
        Photo.Picture.Assign(JpegImage);
        Photo.Visible := True;
      finally
        JpegImage.Free;
        BlobStream.Free;
      end;
    end
  else
    Photo.Visible := False;
end;

end.



Blob Jpeg Field Delphi Example
Download Absolute Database | Learn more


Product Info


Current version: 7.95
Released: February 08, 2023
Price: $ 149

downloadorder


Our Customers



Testimonials

Component Ace is all that it advertises. It is easy to implement and is very fast.

In addition, the customer support is the best I have ever had. All my questions were answered within hours, often immediately. The responses also answered my questions, no need for followup emails.

If your application needs the functionality that Component Ace provides, search no further.

Linda Murphy

        © 2003 - 2024 ComponentAce  | .net zip component | barcode for .net | delphi zip component | delphi database Apr 19, 2024