Working from the instructions in CinFreepascal.pdf ( ftp://ftp.freepascal.org/pub/fpc/docs-pdf/CinFreePascal.pdf ) I have written an interface library to the C++ library libtesseract ( http://code.google.com/p/tesseract-ocr ).

Everything appears to work well but I am unsure about how to free memory which has been reserved by a libtesseract function and returned as a result. The original documentation states that "The calling function must delete [] after use", but the application crashes with an Access Violation if I try to free the memory with Dispose or Freemem. I can confirm that the array of Integer pointed to by the result of tesseract_AllWordConfidences contains valid data.

I would be grateful for any help.

- Malcolm

-------------

Freepascal declaration and code snippet:
function tesseract_AllWordConfidences( APIHandle: TTesseract ): PInteger; stdcall; external LIBTESSINTF;

var
  conf: PInteger;
  FTesseract: TTesseract;
begin
  ...
     conf := tesseract_AllWordConfidences(FTesseract);
  ...
end;

====

C function, and documentation from C++ baseapi.h

  /**
* Returns all word confidences (between 0 and 100) in an array, terminated
   * by -1.  The calling function must delete [] after use.
   * The number of confidences should correspond to the number of space-
   * delimited words in GetUTF8Text.
   */
extern int* EXPORTCALL tesseract_AllWordConfidences(tessHandle APIHandle){
   return APIHandle->AllWordConfidences();
}

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to