Using the Fast TWAIN Feature (Delphi)

Take the following steps to start a project and to add some code that acquires the images using Fast Twain:

1.

Start Delphi.

2.

On the Delphi toolbar, click the LEADTOOLS tab. If you have used a LEAD VCL control before, the icon appears on the toolbar. Otherwise, refer to Installing VCL before continuing with this tutorial.

3.

Select the LEAD Twain control on the LEADTOOLS toolbar. Place the control anywhere on the form.

4.

At the top of your form, add a check box and name it as follows:

 

Name

Caption

 

chkUseBufferSize

Use Buffer Size

5.

Add 2 radio buttons to your form, and name them as follows:

 

Name

Caption

 

rbNative

Native Mode

 

rbMemory

Memory Mode

6.

Add 1 button to your form, and name it as follows:

 

Name

Caption

 

btnAcquire

Fast Acquire

7.

Add 2 Edit boxes to your form, and name them as follows:

 

Name

 

 

edtFName

 

 

edtBufferSize

 

8.

Handle the Form1 OnCreate event, and code the FormCreate procedure as follows:

procedure TForm1.FormCreate(Sender: TObject);
begin
 LEADTwain1.UnlockSupport ( L_SUPPORT_DOCUMENT, 'TestKey' );
   LEADTwain1.InitSession ( Handle ) ;
   LEADTwain1.EnableMethodErrors:= False;
   rbMemory.Checked:= True;
end;

9. Handle the Form1 OnClose event, and code the FormClose procedure as follows:

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 LEADTwain1.EndSession ( );
end;

10. Handle the btnAcquire control's OnClick event, and code the btnAcquireClick procedure as follows.

procedure TForm1.btnAcquireClick(Sender: TObject);
var
 nRet: L_INT;
 nFormat: L_INT;
   uTransferMode: L_UINT;
   bMemory: Boolean;
begin
   bMemory:= rbMemory.Checked;
   if ( bMemory ) then
   begin
      uTransferMode:= LTWAIN_BUFFER_MODE;
      nFormat:= FILE_CCITT_GROUP4;
   end
   else
   begin
      uTransferMode:= LTWAIN_NATIVE_MODE;
      nFormat:= FILE_TIF;
   end;

   nRet:= LEADTwain1.AcquireMulti ( edtFName.Text,
                                    LTWAIN_SHOW_USER_INTERFACE Or LTWAIN_USE_THREAD_MODE,
                                    uTransferMode,
                                    nFormat,
                                    1,
                                    TRUE,
                                    StrToInt(edtBufferSize.Text),
                                    Not chkUseBufferSize.Checked );

   if ( nRet = SUCCESS ) then
      ShowMessage ( 'Fast Scanning process done successfully...' )
   else
   begin
      ShowMessage ( 'AcquireMulti failed, Error = ' + IntToStr(nRet) );
   end;
end;

11. At the beginning of the Unit1 file, add LEADDef, and LEADTyp to the uses section.

12. Run your program to test it.