There are four procedures involved. I'm still working on this, so please excuse how untity this code is.
procedure TfrmMain.BtnABSAcquireClick(Sender: TObject);
// This uses the very simple ABS Twain interface dialog box.
Var
frmABSInterface : TfrmABSInterface;
sColorVal, sDPIvalue : String;
iColorVal : Integer;
iDPIvalue : Integer;
iDocTypeValue : integer;
begin
ClearThumbs;
try
Screen.Cursor := crHourglass;
{ by David Cornelius to disable the multi-image views}
iemvPageThumbs.Visible := False;
{ Initialize }
sColorVal := '0';
sDPIValue := '0';
iDocTypeValue := iDefaultImageFormat;
CanUpdateImage := True;
if dxBarBtnSmooth.Down then dxBarBtnSmooth.Click;
ImageEnView1.Cursor := crHourglass;
{Create MyDialog}
frmABSInterface := TfrmABSInterface.Create2(nil, Addr(sColorVal), Addr(sDPIValue), Addr(iDocTypeValue));
Application.ProcessMessages;
except
{silent exception}
end;
Application.ProcessMessages;
try
If frmAbsInterface.showModal = mrOK Then
Begin
Try
iColorVal := StrToInt(sColorVal);
iDPIValue := StrToInt(sDPIValue);
iDocTypeValue := iDocTypeValue; // ????? Why this code ?????
Screen.Cursor := crDefault;
DoABSscan(iColorVal,iDPIvalue,iDocTypeValue);
Application.ProcessMessages;
except
MessageBox(Application.Handle,'Unable to acquire image. Either the scanner is '+
'not functioning* or is not compatible with ABS Document Manager. '#13#13#13+
'* It may turned off, or asleep.',
'Error',MB_OK);
exit;
end;
end;
finally
Try
FreeAndNil(frmABSInterface);
cxgrdGrid1DBTableView1.NavigatorButtons[12].Click;
finally
Application.ProcessMessages;
if Screen.Cursor <> crDefault then Screen.Cursor := crDefault;
ImageEnView1.Cursor := crDefault;
end;
end;
end;
procedure TfrmABSinterface.btnAcquireClick(Sender: TObject);
begin
{ Sends values back to calling procedure. }
Try
if DisableScaning then
begin
ModalResult := mrCancel;
Exit;
end;
gbOEM_Show_Dialog := chkScannerSoftware.Checked;
gbAutoFeed := chkAutoFeed.Checked;
gbDuplexEnabled := chkDuplexEnabled.Checked;
String(fColorVal^) := IntToStr(cboColors.ItemIndex);
String(fDPIValue^) := IntToStr(cboResolution.ItemIndex);
Integer(fDocType^) := rgDocType.ItemIndex;
SaveProperties;
ModalResult := mrOK;
except
ModalResult := mrCancel;
MessageBox(Application.Handle,'Unable to acquire image.','Error',MB_OK);
end;
end;
procedure TfrmABSinterface.SaveProperties;
var
SelectedDPI: integer;
begin
with frmMain.ImageEnMView1.MIO do
begin
AcquireParams.XResolution := DPI[SelectedDPI];
AcquireParams.YResolution := DPI[SelectedDPI];
AcquireParams.PixelType := TIEAcquirePixelType( cboColors.ItemIndex );
AcquireParams.FeederEnabled := chkAutoFeed.Checked;
AcquireParams.AutoFeed := chkAutoFeed.Checked;
AcquireParams.DuplexEnabled := chkDuplexEnabled.Checked;
AcquireParams.VisibleDialog := chkScannerSoftware.Checked;
TwainParams.ProgressIndicators := True;
end;
with frmMain.ImageEnIO1 do
begin
AcquireParams.XResolution := DPI[SelectedDPI];
AcquireParams.YResolution := DPI[SelectedDPI];
AcquireParams.PixelType := TIEAcquirePixelType( cboColors.ItemIndex );
AcquireParams.FeederEnabled := false;
AcquireParams.AutoFeed := false;
AcquireParams.DuplexEnabled := false;
if chkScannerSoftware.enabled then
AcquireParams.VisibleDialog := chkScannerSoftware.Checked;
TwainParams.ProgressIndicators := True;
end;
end;
Procedure TfrmMain.DoABSscan(SelectedColors, SelectedDPI, SelectedDocType: Integer);
Begin
CanUpdateImage := True;
Application.ProcessMessages;
Try
if SelectedDocType < 2 then
begin
if ImageEnIO1.Acquire = False then
begin
MessageBox(Application.Handle,'We were unable to scan this image. The '+
'scanner may not ready. If your scanner is turned on and warmed up, '+
'it may not be fully compatible with ABSŪ. You should try the '+
'manufacturer''s scanning software as an alternative. Another '+
'alternative is to use your scanner directly, and then import the '+
'scanned image into ABS Document Manager.','Quick & Easy Error',MB_OK);
exit;
end;
end;
except
on E: Exception do
begin
MessageBox(Application.Handle,PChar(E.Message),PChar('Scan Failed'),MB_OK + MB_ICONERROR);
exit;
end;
end;
Application.ProcessMessages;
try
ImageEnView1.AutoStretch := true;
except
end;
Try
case SelectedDocType of
0:begin {JPG}
NewFileName := GetFileName(gsDocManPath, '.JPG');
ImageEnIO1.Params.JPEG_Quality := giJPEG_Better;
ImageEnIO1.SaveToFile(gsDocManPath + NewFileName);
end;
1:begin {PNG}
NewFileName := GetFileName(gsDocManPath, '.PNG');
ImageEnIO1.Params.PNG_Compression:=9;
ImageEnIO1.Params.PNG_Interlaced := False;
ImageEnIO1.SaveToFile(gsDocManPath + NewFileName);
end;
2:begin {PDF}
ImageEnMView1.Clear;
if not ImageEnMView1.MIO.Acquire then exit;
Application.ProcessMessages;
NewFileName := frmMain.GetFileName(gsDocmanPath, '.PDF');
ImageEnMView1.MIO.SaveToFilePDF(gsDocManPath + NewFileName);
end;
end;
Application.ProcessMessages;
// IsNewImage := True;
// Save Image to File.
Application.ProcessMessages;
qImageList.Append ; { Append New image info to database. }
qImageList.FieldByName('FK_ID').AsInteger := StrToInt(gsHHkey);
qImageList.FieldByName('ImageName').AsString := NewFileName;
qImageList.FieldByName('Caption').AsString := 'Scanned '+ DateTimeToStr(Now);
qImageList.FieldByName('DateStamp').AsDateTime:= Date;
qImageList.FieldByName('HHName').AsString := AccountName;
Application.ProcessMessages;
qImageList.Post;
Application.ProcessMessages;
qImageList.Last;
Application.ProcessMessages;
RzStatusPane3.Caption := 'File: ' + qImageList.FieldByName('ImageName').AsString;
Except
MessageBox(Application.Handle,
PChar('Unable to save this document. Please try to save it manually.'),
PChar('FYI'), MB_OK + MB_ICONINFORMATION);
end;
RzProgressBar1.Percent := 0;
Application.ProcessMessages;
end;