Get a Fast Twain Scan from a Scanner (Delphi 6.0)

Take the following steps to start a project and to add some code to find the fastest configuration for your scanner using the LEADTOOLS Fast TWAIN feature:

1.

Start Delphi 6.0.

2.

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

 

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

3.

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. Press install, and then compile and install the package dclusr.dpk.

4.

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

5.

At the top of your form, add 3 button controls and name them as follows:

 

Name

Caption

 

btnSelectSource

Select Source

 

btnFindFastConfig

Find Fast Config.

 

btnAcquireFastConfig

Acquire Fast Config.

6.

Declare the following variable in the public section of Unit1.

nRet: Integer;

7.

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

procedure TForm1.FormCreate(Sender: TObject);
begin
   LEADRasterTwain1.InitSession ( Handle ) ;
   LEADRasterTwain1.EnableMethodErrors:= False;

   { Unlock Document support.
      Note that this is a sample key, which will not work in your toolkit. }
   LEADRasterTwain1.UnlockSupport ( L_SUPPORT_DOCUMENT, 'TestKey' ) ;
end;

8.

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

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

9.

Handle the btnSelectSource OnClick event, and code the btnSelectSourceClick procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

procedure TForm1.btnSelectSourceClick(Sender: TObject);
begin
   LEADRasterTwain1.SelectSource ( ) ;
end;

10.

Handle the btnFindFastConfig OnClick event, and code the btnFindFastConfigClick procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

procedure TForm1.btnFindFastConfigClick(Sender: TObject);
begin
   LEADRasterTwain1.UserFastConfigsCount := 0;
   LEADRasterTwain1.EnableFastConfigEvent := False;
   nRet:= LEADRasterTwain1.FindFastConfig ('c:\temp', L_LTWAIN_SHOW_USER_INTERFACE Or L_LTWAIN_USE_THREAD_MODE, 8, 5);

   if ( nRet = 0 ) Then
      ShowMessage ('Find Fast Configuration process completed.' )
   else
      ShowMessage ('An error occurred during the Finding Fast Configuration process.' ) ;
end;

11.

Handle the btnAcquireFastConfig OnClick event, and code the btnAcquireFastConfigClick procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

procedure TForm1.btnAcquireFastConfigClick(Sender: TObject);
begin
   LEADRasterTwain1.FastTransferMode := LEADRasterTwain1.BestFastConfig.TransferMode;
   LEADRasterTwain1.FastFormat := LEADRasterTwain1.BestFastConfig.FileFormat;
   LEADRasterTwain1.FastBitsPerPixel := LEADRasterTwain1.BestFastConfig.BitsPerPixel;
   LEADRasterTwain1.FastBufferSize := LEADRasterTwain1.BestFastConfig.BufferSize;

   LEADRasterTwain1.FastUsePreferredBufferSize := True;
   LEADRasterTwain1.EnableAcquireMultiEvent:= False;

   nRet := LEADRasterTwain1.AcquireMulti ('c:\temp\test', L_LTWAIN_SHOW_USER_INTERFACE, True);

   if ( nRet = 0 ) Then
      ShowMessage ( Image acquisition  using the Fast TWAIN Configuration is completed.' )
   else
      ShowMessage ( 'An error occurred while acquiring images using the Fast TWAIN Configuration.' ) ;
end;

11.

Add LTRASTERLib_TLB to the uses section of Unit1.

12.

Save your project and run your program to test it.