Using LEADTOOLS with Data Controls(C++ Builder)

You can associate the LEAD control with a data control so that the LEAD control's bitmap is bound to a specified field in the data control's data set.

Take the following steps to start a project and to add some code that associates the LEAD control with a data control:

1.

Start C++Builder 3.

2.

On the Project menu, select Remove From Project and remove Unit1.cpp and Form1.

3.

On the Database menu, choose Form Wizard. In the first wizard dialog, select the following options and click Next:

 

 

image\sqrblit.gif Create a simple form

 

image\sqrblit.gif Create a form using TTable Object

 

4.

In the second wizard dialog, select the file IMAGES.DB shipped with LEADTOOLS and click Next.

5.

In the following dialog, click the ">>" button to select both fields, then click Next.

6.

In the following dialog, choose Vertically, then click Next.

7.

In the following dialog, choose Top, then click Next.

8.

In the last dialog, make sure that the options are as follows, them click Finish.

 

 

image\sqrblit.gif Generate a main form

 

image\sqrblit.gif Form Only

 

9.

Click on the ImageBMP control and delete it. In its place, insert a LEAD Main VCL Control (LEADImage) from the LEADTOOLS tab and position it as you would like it to appear in your application.

10.

Change the following properties of the LEAD Main Control as follows:

 

Property

Value

DataSource

DataSource1

DataField

BMP

You must assign the DataSource before the DataField.

11.

From the LEADTOOLS tab, add a LEADDlgFile control and a LEADDlgService control to the form.

12.

Add a Button control to the form and change its name to btnFlip.

 

13.

Add the following code to the FromCreate procedure. Do not delete code that already exists in the function.

   LEADImage1->BorderStyle  = bsSingle;
   LEADImage1->BackColor = (TColor)RGB(255, 255, 125);
   LEADImage1->AutoRepaint = True;
   LEADImage1->AutoSize = False;
   LEADImage1->AutoSetRects = True;
   LEADImage1->PaintSizeMode = smFit;
   LEADImage1->DataLoadBits = 0;
   LEADDlgService->InitDialogs(0);

14.

Handle the DBNavigator OnClick event, and code the DBNavigator OnClick procedure as follows:

void __fastcall TForm1::DBNavigatorClick(TObject *Sender, TNavigateBtn Button)
{
   if(Button != nbInsert) /* do nothing */
      return;
   LEADDlgFile1->DlgFlags = 0;
   LEADDlgFile1->DialogTitle = "Add an image";
   LEADDlgFile1->PreviewEnabled = True;
   LEADDlgFile1->Filter = "All |*.*|CMP|*.cmp|JPEG|*.jpg";
   LEADDlgFile1->FilterIndex  = 2; /*look for *.cmp first*/
   LEADDlgFile1->InitialDir = "C:\\Program Files\\LEAD Technologies, Inc\\LEADTOOLS14\\images\\";
   LEADDlgFile1->LoadPasses = 0;
   LEADDlgFile1->LoadRotated = True;
   LEADDlgFile1->LoadCompressed = False;
   LEADDlgFile1->DlgFlags =   + 
      DLG_OPEN_SHOW_PROGRESSIVE   +   
      DLG_OPEN_SHOW_MULTIPAGE   +   
      DLG_OPEN_SHOW_LOADROTATED   +   
      DLG_OPEN_SHOW_LOADCOMPRESSED   +   
      DLG_OPEN_SHOW_FILEINFO   +   
      DLG_OPEN_SHOW_PREVIEW   +   
      DLG_OPEN_SHOW_DELPAGE   +   
      DLG_OPEN_VIEWTOTALPAGES   +   
      DLG_OPEN_LOADBITMAP;
   LEADDlgFile1->LEADImage = LEADImage1; /*assign the main control for processing*/
   LEADDlgFile1->EnableMethodErrors = False;
   /* when the user does not load and image, abort the process */
   if(LEADDlgFile1->ShowOpenDlg(this) != SUCCESS_DLG_OK)
   {
      Table1->Cancel();
      return;
   }
   /* Enable image processing before posting to the database */
   btnFlip->Enabled = True;
   /* Specify the appropriate properties for saving the image in the database */
   switch(LEADImage1->BitmapBits)
   {
      case 1:
         LEADImage1->DataSaveBits = 1;
         LEADImage1->DataSaveFormat = FILE_LEAD1BIT;
         break;
      case 4:
         LEADImage1->DataSaveBits = 4;
         LEADImage1->DataSaveFormat = FILE_PCX;
         break;
      default:
         if(LEADImage1->IsGrayScale == GRAY_NO) /* save as color */
            LEADImage1->DataSaveBits = 24;
         else /*save as grayscale*/
            LEADImage1->DataSaveBits = 8;
         LEADImage1->DataSaveFormat = FILE_CMP;
         LEADImage1->DataSaveQuality = QMS;
   } /* end of case statement */
   EditNAME->SetFocus();
}

15.

Handle the btnFlip OnClick event, and code the btnFlipClick procedure as follows:

void __fastcall TForm1::btnFlipClick(TObject *Sender)
{
   LEADImage1->Flip();
}

 

16.

Handle the LEADImage1 OnChange event, and code to the LEADImage1Change procedure as follows:

void __fastcall TForm1::LEADImage1Change(TObject *Sender)
{
   /* Avoid processing events that occur before the bitmap is fully loaded */
   if(LEADImage1->Bitmap == 0)
      return;
   /* Demonstrate how the DataChanged property works */
   if(LEADImage1->DataChanged && (DataSource1->State != dsInsert))
      ShowMessage("You flipped the image");
}

17.

Handle the DataSource1 OnStateChange event, and code the DataSource1StateChange procedure as follows:

void __fastcall TForm1::DataSource1StateChange (TObject *Sender)
{
      btnFlip->Enabled = (DataSource1->State == dsEdit);
}

18.

Run your program to test it.