Using the Fast TWAIN Feature (Delphi 6.0)

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

1.

Start Delphi 6.0.

2.

If you didn’t import LEAD Raster Twain before, import it as follows:

 

On the Project pull-down menu, use the Import Type library… and select the LEAD RasterTwain Object Library (14.5). Press install, and then compile and install the package dclusr.dpk.

3.

From the ActiveX controls tab, add the LEAD Raster Twain control and the LEAD Twain Capability control to your form.

4.

Add the following declaration to the private section of Unit1:

nRet: Integer;

5.

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

 

Name

Caption

 

chkUseBufferSize

Use Buffer Size

6.

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

 

Name

Caption

 

rbNative

Native Mode

 

rbMemory

Memory Mode

7.

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

 

Name

Caption

 

btnAcquire

Fast Acquire

8.

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

edtBufferSize
edtFName

9.

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

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

10.

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

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

11.

Handle the btnAcquire control's OnClick event, and code the btnAcquireClick procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

procedure TForm1.btnAcquireClick(Sender: TObject);
begin
   if ( rbMemory.Checked = True ) then
   begin
      LEADRasterTwain1.FastTransferMode:= L_LTWAIN_BUFFER_MODE ;
      LEADRasterTwain1.FastFormat:= FILE_CCITT_GROUP4 ;
   end
   else
   begin
      LEADRasterTwain1.FastTransferMode:= L_LTWAIN_NATIVE_MODE ;
      LEADRasterTwain1.FastFormat:= FILE_TIF;
   end;

   LEADRasterTwain1.FastBitsPerPixel:= 1;
   LEADRasterTwain1.FastUsePreferredBufferSize:= chkUseBufferSize.Checked;
   if ( LEADRasterTwain1.FastUsePreferredBufferSize ) then
      LEADRasterTwain1.FastBufferSize:= StrToInt(edtBufferSize.Text);

   nRet:= LEADRasterTwain1.AcquireMulti (edtFName.Text, L_LTWAIN_SHOW_USER_INTERFACE Or L_LTWAIN_USE_THREAD_MODE, True);
   if ( nRet = 0 ) then
      ShowMessage ( 'Fast Scanning process completed successfully...' )
   else
      ShowMessage ( 'The AcquireMulti method failed, Error = ' + IntToStr ( nRet ) ) ;
end;

12.

Add LTDLLDef to the uses section of Unit1.

13.

Save your project and run your program to test it.