OCX NilObject

  1. 2 months ago

    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...

  2. Eugene D

    Aug 12 Pre-Release Testers, Xojo Pro Canada scispec.ca
    Edited 2 months ago by Eugene D

    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

    7) Press Run

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

    Edit: Fix spelling mistakes

  3. Eugene D

    Aug 12 Pre-Release Testers, Xojo Pro Canada scispec.ca

    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.

  4. 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....

  5. @Roman V 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....

  6. Eugene D

    Aug 12 Pre-Release Testers, Xojo Pro Canada scispec.ca

    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.

or Sign Up to reply!