MODI - tif file stays locked after .Close

S

Scott Kappele

I'm using a MODI reference in my VB .Net 2003 project, creating an MODI
document object instance and using the .Create("myfilename.tif") method to
load the document with a single image from a tiff file. After OCRing the
text, I call the close method.
Problem is that MODI doesnt appear to release the file lock until the
application closes, and i need to reuse the file name.

dim myMODI as MODI.Document
myMODI = New MODI.Document
myMODI.Create("c:\testfile.tif")
myMODI.OCR()
{ does some work looking at the words in the myMODI.Images(0).Layout.Text
property }
myMODI.Close(False)
myMODI = nothing
Kill ("c:\testfile.tif")

The kill statement fails saying that another program has the file open.
How can i get MODI to let go of the file?

Any help is appreciated.
 
S

Scott Kappele

Found a solution to my problem. I simply wrapped the MODI object in an
ActiveX dll written in VB6 and called that from my app instead of the MODI
instance directly.
Did an ActiveX exe first, thinking that it had to run "out of process" to
release properly, but curiosity made me try the in process version to, and it
worked fine.
Wrapping MODI in a .Net helper class didn't work, nor did wrapping it in a
..vb class.
I'd still like to hear if anyone else has solved this in VB .Net with a
different method.
 
J

jimyho

Hi,

I know this problem,and I solve it,
Just move the Kill ("c:\testfile.tif") out of the OCR procedure.

I use Delphi 6.

sBookNo:=OCR(strFile);
DeleteFile(strFile); ---- Now it 's OK.

//-------------------------------------------------------
function TfrmMain.OCR(Image:string):string;
var
sResult:string;
doc: Variant;// layout: Variant;
begin
sResult:= '';
if FileExists(Image) then begin
try
doc := CreateOleObject('MODI.Document');
doc.Create(Image);
doc.OCR(MODI_TLB.miLANG_ENGLISH,True,True);
if doc.Images.Count > 0 then begin
sResult := doc.Images.Item[0].Layout.Text;
end;
doc.Close(True);
doc := UnAssigned;
except
doc.Close(True);
doc := UnAssigned;
end;
end;
result :=trim(sResult);
end
 
D

Danielw

Hi SCOTT!

I 've just started using the MODI module. I build some experience an
indeed that file keeps locked.

I tried different things to get the file `free`, none succesful yet
Anyhow, I had some other ideas: one of them is killing the thread tha
has been started by MODI code in the VB.NET app. As soon as I find
pure VB.Net work-a-round, I will post it, no doubt.

Anyhow, I love you solution, but am not experienced with ActiveX dll
and VB6. (I do have programmed VB6 but its a heck of a time ago.
I saw you solution, but how exactly do I implement this? Could you hel
me? Maybe you are able to post a zip with the VB6 project?
I guess this might be the most simple solution (and working!) so fa
;-)


btw: this is the function I wrote in VB.net that returns the text fro
the first page of a default tiff file:


Code
-------------------
Public Function OCRImage() As String

Dim objDoc As MODI.Document
Dim objImg As MODI.Image

Try
'Create a MODI instance
objDoc = New MODI.Document
objDoc.Create(TiffFileName)

'Copy only the first image
objImg = objDoc.Images(0)
objImg.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, False, False)

'Simply return all of the text found
OCRImage = objImg.Layout.Text

Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Functio
 
D

Danielw

I think I already found the answer. Had though of this idea earlier, bu
thought it was too simple... :-(

// Force garbage collection so image file is closed properly
GC.Collect();
GC.WaitForPendingFinalizers();

(I think I this idea was posted by Scott on another forum ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top