What is the deal with instantiating active-x controls in code? I am trying to write this function that I can call from an FRX:
FUNCTION mkImgFile(tcText, tcBarImageFile )
loBarCodeCtrl = CREATEOBJECT( "db2ocx.db2ocxctrl.1" )
loBarCodeCtrl.caption = tcText
loBarCodeCtrl.SaveImage( tcBarImageFile ) && Writes the barcode to a file
lnErrorCode = loBarCodeCtrl.ErrorCode && retrieve error code
RETURN lnErrorCode
Do I need to put it in an OleContainer or something? If I drop it on a form (in an olecontainer), it works fine. If I use the class browser to generate the code of the form, running the code brings up a dialog box asking me to pick a control. I really don't want to be creating/destroying forms anyway. Ideally I will create the object at the beginning of the report and destroy it when the report is done. But for now I cant even just run this from the command prompt.
Here is what tech support had to say.
> Malcolm,
>
> I get an error when I try and do anything with the ocx.
>
> ox = CREATEOBJECT( "db2ocx.db2ocxctrl.1" )
> ox.codeType=2
>
> error: "OLE error code 0x8000ffff: Catastrophic failure."
>
> With the dll? one, I had to call .dBarInit() like this:
>
> loBarCodeCtrl = CreateObject("dBarcode-2d.Image") && start dBarcode
> loBarCodeCtrl.dBarInit() && initialize control
>
>
> Carl
Reply:
I think you are confusing the OLE server (called with
CreateObject("dBarcode-2d.Image") ) and the OCX control (which is used in
VB by placing it on a form).
Malcolm