Get a Fast Twain Scan from a Scanner (Delphi 4.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 4.0.

2.

On the Project pull-down menu, use the Import Type library… and select the LEAD Raster Object Library (14.5). Press OK.

3.

On the Project pull-down menu, use the Import Type library… and select the LEAD RasterTwain Object Library (14.5). Press OK.

4.

Declare the following variables in the public section of Unit1:

RasterTwain: LEADRasterTwain;
nRet: Integer;

5.

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

procedure TForm1.FormCreate(Sender: TObject);
begin
   RasterTwain:= CreateComObject ( CLASS_LEADRasterTwain ) as LEADRasterTwain;
   RasterTwain.InitSession ( Handle ) ;
   RasterTwain.EnableMethodErrors:= False;

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

end;

6.

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

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

7.

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

 

Name

Caption

 

btnSelectSource

Select Source

 

btnFindFastConfig

Find Fast Config.

 

btnAcquireFastConfig

Acquire Fast Config.

8.

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
  RasterTwain.SelectSource ( ) ;
end;

9.

Handle the btnFindFastConfig OnClick event, and code 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
   RasterTwain.UserFastConfigsCount := 0;
   RasterTwain.EnableFastConfigEvent := False;
   nRet:= RasterTwain.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;

10.

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
   RasterTwain.FastTransferMode := RasterTwain.BestFastConfig.TransferMode;
   RasterTwain.FastFormat := RasterTwain.BestFastConfig.FileFormat;
   RasterTwain.FastBitsPerPixel := RasterTwain.BestFastConfig.BitsPerPixel;
   RasterTwain.FastBufferSize := RasterTwain.BestFastConfig.BufferSize;

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

   nRet := RasterTwain.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.

At the beginning of the Unit1 file, add ComObj, LTRASTERTWAINLib_TLB, LTDLLDef to the uses section. This lets you handle the Com objects, the Raster Twain object library, and use the LEAD Defines.

12.

Save your project and run your program to test it.