Skip to content

Instantly share code, notes, and snippets.

@InliteResearch
Last active October 26, 2025 18:53
Show Gist options
  • Save InliteResearch/5497794 to your computer and use it in GitHub Desktop.
Save InliteResearch/5497794 to your computer and use it in GitHub Desktop.

The following example demonstrates typical use of ClearImage to read barcodes in Delphi application. It reads Code39 barcodes from an image file. 'OR' type values in Type_ property to detect multiple barcode symbologies.
Alternatively set AutoDetect1D property to ciTrue to detect barcodes of the most popular symbologies.

To import ClearImage into Delphi project:
1.  In Project menu select Import Type Library 
2.  Select ClearImage COM Server in list box 
3.  Click on the Create Unit button

To use ClearImage in Delphi project
1.  Add the ClearImage_TLB unit to the uses clause
2.  Initialize the COM interface: 
     in GUI: Call Application.Initialize; 
     in DOS: 
          Add to uses ActiveX, Windows
          Call CoInitialize(nil); before any ClearImage calls 
          Call CoUnInitialize; before exiting application

Exception handling
Any error detected by ClearImage COM (e.g. Image.Open tries to open file that does not exist) generates COM exception. Use try - except to trap and process such errors.

If image to be shared between multiple processing modules, image object can be created separately and attached to processing object:
    Image: ICiImage;
    Image := Ci.CreateImage;
    Image.Open(aFileName, 1);
    Barcode.Image := Image;

uses
...,ClearImage_TLB, comobj;
......
function DecodeBarcode(const aFileName: string): AnsiString;
var
Ci: ICiServer;
Image: ICiImage;
Barcode: ICiBarcodePro;
begin
Result := '';
try
try
begin
Ci := CoCiServer.Create;
// Open image
Image := Ci.CreateImage;
Image.Open(aFileName, 1);
// Create Barcode recognition object
Barcode := Ci.CreateBarcodePro;
Barcode.Image := Image;
Barcode.Type_ := cibCode39;
// To automatically detect barcode type
// Barcode. AutoDetect1D := ciTrue;
// Read one barcode. To find all barcodes call Barcode.Find(0)
Barcode.Find(1);
if Barcode.Barcodes.Count > 0 then
Result := Barcode.Barcodes.Item[1].Text;
end;
except
// Process errors
on E: Exception do ShowMessage (Format('Error:%s.File:%s',
[E.Message,FileName]));
else
ShowMessage ('Unknown Error');
end;
finally
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment