Automation causes Navision to Crash

hkjhkj Member Posts: 6
I have a created a Codeunit that calls an AutomationVar with the property "WithEvents" set to yes.

The Code is pretty simple:

"
IF ISCLEAR(AutomationVar) then
CREATE(AutomationVar);

AutomationVar.StartTest(Parameters1-5).
"

When i Run this Codeunit Navision crashes with the message

"Microsoft Business Solutions-Navision has encountered a problem and needs to close"

The strange part i that I can create a Form that OnOpenForm calls the codeunit with no problems whatsoever, and I can also insert a CommandButton on the Form where I call the codeunit. Again with no errors.

Does anyone know why I can't runl the Codeunit directly?

Comments

  • kinekine Member Posts: 12,562
    May be it is problem of variable scope. If you run the codeunit, the object is created in memory and is destroyed right after calling the object... but if you include this codeunit into form or somewhere, the variable is destroyed after closing the object, it means, it takes some time between creating and destroying the object... may be that the object has problem with this...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    What are you using the interface for?


    If you want to do something with the events you need a singleinstance codeunit I think. Otherwise the events make no sence.
  • kinekine Member Posts: 12,562
    Or they make sence if you want to catch the events when the form is open...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • hkjhkj Member Posts: 6
    Thanks for the quick replies.

    The purpose of the Autmation is to validate som technical informations speciefied on the Sales Lines, to determine if the configuration of an Item makes sense.

    When running the Codeunit it should be possible for a person so see somme graphs created in sanother program, and after the validation has completed, navision should retrieve a message that either confirms or abort the configuration.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    In Navision It used to be only possible to have a form in a dll to run modaly. So the c/al code will continue after you have closed the external form. This way you don;t need to raise an event.

    But they might have changed it. I do not have experience after 3.70 with this.
  • hkjhkj Member Posts: 6
    I actually need a value into Navision telling me whether I can procced with the Order or need to reconfigure my Order.
  • DenSterDenSter Member Posts: 8,307
    edited 2005-12-16
    Did you set the codeunit to single instance? If you have a variable with events it has to have some memory to operate in. A single instance codeunit will reserve that space and keep it alive as long as the sessino is open.
    <edit>
    Mark... just saw that you suggested this... I don't even have my coffee yet guys, go easy on me, it's early in the morning :shock:
    </edit>
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    I solved this by making the form unvisible on closing.

    This way the object is not destroyed yet,

    You can make some function that returns the value you want to have

    After that you can destroy the object by using CLEAR()

    Unfortunatly I don't have access to this code anymore.
Sign In or Register to comment.