Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 3 Monaten, 1 Woche
Letzter Beitrag:
vor 3 Monaten
Beteiligte Autoren:
Ericus, Peter Holemans, Arie, Fabrice Harari

[WD 21]C# or VB Syntax in Windev

Startbeitrag von Ericus am 04.09.2017 14:12


I apologise for asking so many questions lately but here goes again.

I am trying to incorporate Leadtools OCR and scanning in Windev. Loaded all the .NET assemblies I need and just trying a simple example.

This is the example code in C#

formsCodec = new RasterCodecs();

ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);
ocrEngine.Startup(formsCodec, null, null, @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime");

//Point repository to directory with existing master forms
formsRepository = new DiskMasterFormsRepository(formsCodec, @"C:\Users\Public\Documents\LEADTOOLS Images\Forms\MasterForm Sets\OCR");
autoEngine = new AutoFormsEngine(formsRepository, ocrEngine, null, AutoFormsRecognitionManager.Default | AutoFormsRecognitionManager.Ocr, 30, 80, true);

What I'm not sure of is how to do this in Windev for instance:

formsCodec must be something i.e this works;

FormsCodec is RasterCodecs = new RasterCodecs() does not give an error in Windev


OcrEngine is OcrEngineManager = new OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False) does not work.

It seems in C# you just create a variable but in windev we have to declare what type of variable and this is where I fall short.

In VB it look like this:

Dim MY_LICENSE_FILE As String = "d:\temp\TestLic.lic"
' Unlock LEADTOOLS special Support
Dim MY_DEVELOPER_KEY As String = "abc123xyz"

formsCodec = New RasterCodecs()
' Create an OCR Engine for each processor on the machine. This allows for optimal use of thread during recognition and processing.
ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)
ocrEngine.Startup(formsCodec, Nothing, Nothing, "C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime")

' Point repository to directory with existing master forms
formsRepository = New DiskMasterFormsRepository(formsCodec, "C:\Users\Public\Documents\LEADTOOLS Images\Forms\MasterForm Sets\OCR")
autoEngine = New AutoFormsEngine(formsRepository, ocrEngine, Nothing, AutoFormsRecognitionManager.Default Or AutoFormsRecognitionManager.Ocr, 30, 80, True)

Thanks in advance

Ericus Steyn


Hi Ericus,

OcrEngine is OcrEngineManager = new OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False) does not work.

it canno't work. If you use NEW to instantiate an object, the variable MUST be declared as a DYNAMIC object first

So maybe
OcrEngine is OcrEngineManager DYNAMIC= new OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)
Will work.

And again
FormsCodec is RasterCodecs = new RasterCodecs()
Is also missing the DYNAMIC keywords.

We are talking about OOP here, so all regular OOP rules apply.

On top of that, this line:
ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);

seems to mean that you can NOT instantiate the ocrEngine object yourself, but that instead you need to create the dynamic object, then ask the OcrEngineManager.CreateEngine function to return the instance to you

So, something like
ocrEngine is object dynamic= OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);

has a better chance to work

Best regards

von Fabrice Harari - am 04.09.2017 14:36
Hi Ericus,

Out of my head something like this maybe...
Also check if the assembly is expecting unicode (like in most cases now) or classical ansi compared to your WX configuration.
Personally haven't started any ANSI project anymore in WX since V17/V18. All are unicode.

formsCodec is object dynamic
formsCodec = new RasterCodecs()

ocrEngine is object dynamic
ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false)
ocrEngine.Startup(formsCodec, null, null, "C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime")
// --> The @ in the C# example describes it is a string so that special characters (\ in this case) don't need to be escaped like in C/C++/Java

//Point repository to directory with existing master forms
formsRepository is object dynamic
formsRepository = new DiskMasterFormsRepository(formsCodec, "C:\Users\Public\Documents\LEADTOOLS Images\Forms\MasterForm Sets\OCR")
autoEngine is object dynamic
autoEngine = new AutoFormsEngine(formsRepository, ocrEngine, null, AutoFormsRecognitionManager.Default Or AutoFormsRecognitionManager.Ocr, 30, 80, true);
//--> Not sure how to deal with the Or in the above case. Guess the example code wants you to pass one of the two...


Peter Holemans

von Peter Holemans - am 04.09.2017 14:36
Thanks for the contributions.

It seems that OOP programming is more a case of OOPS programming for me. The below is working up to the last line below when I get an error 'Only object of the same class can be assigned to object'

sMY_LICENSE_FILE is string = "D:\LEADTOOLS 19\Common\License\LEADTOOLS.LIC"
sMY_DEVELOPER_KEY is UNICODE string = "gcxLXplT2JbMbVfDTdFok4CRW8AeLjIIud383qJp4jPtoJTYamOd1yiYl3r+CmFEapyScu+aaiTXpLBGrOGYl0gjTaEon03u"
Leadtools.RasterSupport.SetLicense(sMY_LICENSE_FILE, sMY_DEVELOPER_KEY)
clPclFormsCodec is RasterCodecs dynamic
clPclFormsCodec = new RasterCodecs()
pclOcrEngine is object dynamic
pclOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)

If someone might once again have another pointer for me.

Thanks in advance

Ericus Steyn

von Ericus - am 12.09.2017 10:32
Hi Ericus,

a bit of a guess, but try this

pclOcrEngine is object dynamic OcrEngineManager

instead of this

pclOcrEngine is object dynamic

von Arie - am 12.09.2017 10:39
Thanks Arie

It works for the first 2 lines below but then the 3rd line already shows an error in the code.

I know if I type in pclOcrEngine. it should come up with the functions that I can call and Startup is not one of them. In my previous mail there was no compilation errors but the application failed on the CreateEngine.

pclOcrEngine is object dynamic Leadtools.Forms.Ocr.OcrEngineManager
pclOcrEngine = Leadtools.Forms.Ocr.OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False) //
pclOcrEngine.Startup(clPclFormsCodec, Null, Null, "D:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime")

All to confusing.

Thanks in any case.

Ericus Steyn

von Ericus - am 12.09.2017 13:21
Hi Ericus,

Here's how I would code it (but would need to look at the documentation of the OCR assembly.

pclOcrEngine is object dynamic
pclOcrEngine = new OcrEngineManager
pclOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)

Not sure on passing the path in your params next but it might be possible you need to escape the backslash characters as you don't have the @ preprocessor in WX like in the C# example. A backslash is a reserved character in C-like languages like C#, Java, ... So:

pclOcrEngine.Startup(clPclFormsCodec, Null, Null, "D:\\LEADTOOLS 19\\Bin\\Common\\OcrAdvantageRuntime")

I'm sure that doing the same stuff in c# requires less lines of code and would be even more readable and consistent. You could even simply reuse the tons of samples you'll probably find out there on the web...

Remember that using advanced .Net classes, structures, generics, ... in WX has quite some limitations and may provoke the WX runtime to crash at will.

How I overcome this usually:
- Use Visual Studio (Community Edition 2017 if you want the freebie)
- Create a C# .Net assembly project (.dll) that you'll use out WX and that only passes basic input/output types (string, numerics, basic objects,...) or a predefined not too advanced object class you defined in your assembly
- All the logic to do the OCR stuff etc (the original C# sample you showed) is done in this .Net assembly
- To it you pass a basic request out of WX
- In WX you accept the basic result or basic class with its members back

I guarantee you that I never had a problem with that...
Works even 10 times faster to develop instead of trying to figure out why the WX runtime can't process your request or gives weird compiling errors...

Just my 2 cents,


von Peter Holemans - am 12.09.2017 15:00
Thanks Peter I am going to give that a go.

von Ericus - am 12.09.2017 19:06
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.