OCX NilObject

I am not very experienced in OCX stuff but I am trying now to incorporate one in a project…

I want to incorporate receipt printers in my app, for that I thought I’d use the OCX they distribute…

The component is loaded in the project without errors (after changing the date values to doubles and removing the ‘end of procedure’ lines)… but so far the only way to connect to it was by creating an instance of an OLEobject.

The problem with this approach is I cannot get the data reply that the component returns back to Xojo. The OCX provides structures for the return data, but even though the structures seem show up fine in the debugger at runtime, I always get a nilObject Exception when trying to use them…

As an alternative option I tried creating an instance and using the OCX without creating the OLEObject, and it still doesn’t work…

I don’t even know here to start…

Hi Roman,

I am not familiar with the specific printer OCX that you described, although OCX is straightforward to add into Xojo.

Here is a quick example using the built-in Windows Media Player OCX to play an mp3 sound that has a length of about 3-seconds:

  1. Open a New Xojo desktop application
  2. On the MenuItem, click Insert->ActiveX Component (a new window should appear)
  3. With the Controls tab selected at the top, select Windows Media Player (WMPlayer.OCX) and press the OK button.
  4. Converting this to code in Xojo takes about 10 seconds or so, please be patient
  5. Drag-and-Drop the WIndowsMediaPlayer control (upper left side of the IDE) onto Windows1
  6. Add a new pushbutton on Window1, and add the following code:

WindowsMediaPlayer1.URL = "C:\\test\\Record.mp3" //Location of File WindowsMediaPlayer1.controls.play //Play the sound

  1. Press Run

Choose your own mp3 sound to play, and have the sound longer than about 3 seconds.

Edit: Fix spelling mistakes

If the OCX file does not appear in Xojo, then the OCX file will need to be registered.

Open a command prompt, and go to the folder where the OCX is located. Type the following command to register the OCX file (example filename: Printer.OCX)

Regsvr32 Printer.OCX

The OCX file should now appear in Xojo to insert an ActiveX component.

Hey Eugene… thanks for your reply… The OCX DOES show up and I managed to insert it (after changing the date values to doubles and removing the ‘end of procedure’ lines)… the problem is, somehow, it does not connect…

Depending on the version of the OCX I either get a NilObject Exception in the line

if mThis = Nil Then Raise New NilObjectException

of the first method I onvoke…

OR a ComObjectException in the same firstmethod I invoke…

[quote=345248:@Roman Varas]Hey Eugene… thanks for your reply… The OCX DOES show up and I managed to insert it (after changing the date values to doubles and removing the ‘end of procedure’ lines)… the problem is, somehow, it does not connect…

Depending on the version of the OCX I either get a NilObject Exception in the line

if mThis = Nil Then Raise New NilObjectException

of the first method I invoke…

OR a ComObjectException in the same first method I invoke…[/quote]

Hi Roman,

Sorry, I don’t see any code to understand the purpose of the OCX and the reason behind the resulting mThis call. There are quite a few possibilities that it could be:

  1. Possibly changing the date values to doubles?
  2. Depends on how the object instance was created?
  3. Does the instance need to be connected to a printer?
  4. The list goes on.

Without code, that’s about as far as I can help. I wish you the best.