www.pudn.com > Absolute.Database.v5.18.Full.Source.Delphi.rar > Main.cpp, change:2008-06-18,size:2838b


//--------------------------------------------------------------------------- 
#include <vcl.h> 
#pragma hdrstop 
 
#include "Main.h" 
//--------------------------------------------------------------------------- 
#pragma package(smart_init) 
#pragma link "ABSMain" 
#pragma resource "*.dfm" 
TfrmMain *frmMain; 
 
const AnsiString DataBaseFileName = "..\\..\\Data\\Demos.abs"; 
 
//--------------------------------------------------------------------------- 
__fastcall TfrmMain::TfrmMain(TComponent* Owner) 
        : TForm(Owner) 
{ 
} 
//--------------------------------------------------------------------------- 
void __fastcall TfrmMain::FormCreate(TObject *Sender) 
{ 
  dbDemos->Close(); 
  dbDemos->DatabaseFileName = ExtractFilePath(Application->ExeName) + DataBaseFileName; 
  dbDemos->Open(); 
  tPhotoAlbum->Open(); 
} 
//--------------------------------------------------------------------------- 
 
void __fastcall TfrmMain::btLoadImageClick(TObject *Sender) 
{ 
TFileStream *FileStream; 
TStream *BlobStream; 
 
 if (odBlob->Execute()) 
   { 
     tPhotoAlbum->Edit(); 
     try 
     { 
       BlobStream = tPhotoAlbum->CreateBlobStream(tPhotoAlbum->FieldByName("Photo"),bmWrite); 
       FileStream = new TFileStream(odBlob->FileName,fmOpenRead+fmShareDenyNone); 
       BlobStream->CopyFrom(FileStream,FileStream->Size); 
       delete FileStream; 
       delete  BlobStream; 
       tPhotoAlbum->Post(); 
       tPhotoAlbumAfterScroll(tPhotoAlbum); 
     } 
     catch(...) 
     { 
       tPhotoAlbum->Cancel(); 
     } 
   } 
} 
//--------------------------------------------------------------------------- 
 
void __fastcall TfrmMain::btSaveImageClick(TObject *Sender) 
{ 
TFileStream *FileStream; 
TStream *BlobStream; 
 
  if (sdBlob->Execute()) 
    { 
      FileStream = new TFileStream(sdBlob->FileName,fmCreate); 
      BlobStream = tPhotoAlbum->CreateBlobStream(tPhotoAlbum->FieldByName("Photo"),bmRead); 
      FileStream->CopyFrom(BlobStream,BlobStream->Size-BlobStream->Position); 
      delete BlobStream; 
      delete FileStream; 
    }; 
} 
//--------------------------------------------------------------------------- 
 
void __fastcall TfrmMain::tPhotoAlbumAfterScroll(TDataSet *DataSet) 
{ 
TJPEGImage *JpegImage; 
TStream *BlobStream; 
 
  if (!tPhotoAlbum->FieldByName("Photo")->IsNull) 
    { 
      BlobStream = tPhotoAlbum->CreateBlobStream(tPhotoAlbum->FieldByName("Photo"),bmRead); 
      JpegImage = new TJPEGImage; 
      try 
      { 
        JpegImage->LoadFromStream(BlobStream); 
        Photo->Picture->Assign(JpegImage); 
        Photo->Visible = True; 
      } 
      __finally 
      { 
        delete JpegImage; 
        delete BlobStream; 
      }; 
    } 
  else 
    Photo->Visible = False; 
} 
//---------------------------------------------------------------------------