Current Codeunit as Variable/Parameter

SonGoten13SonGoten13 Member Posts: 44
Hi,
Does someone know if it is possible to put the current running instance of a codeunit into a variable to use it then as a parameter?
The same that Rec does for a Table Object?
Would need it for a workaround.

Comments

  • geordiegeordie Member Posts: 655
    I think would be possible to achieve that, passing the codeunit parament by reference (Var = true).
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Yes, you can pass a codeunit as parameter and when selecting by variable all internal globals will be mainained.

    However, it is not a really elegant solution and other developers will wonder why you did that.

    It is done in standard NAV with Assembly Management. Here the reason was to avoid creating multiple registers.

    IMHO there are more elegant solutions for that.
  • SonGoten13SonGoten13 Member Posts: 44
    thx for your responses, but i think you misunderstood me.
    I know that you can pass a codeunit as parameter and i agree that its not that elegant. I could do it differnt but i would have to change quite some code what i would like to avoid.
    Anyway my question is:
    Is it possible to put the current running instance of a codeunit into a variable, from code within that codeunit? I dont have Rec like i have when i am in a table, but i would like to achieve the same thing.
    I am in cuX. From there i want to call a function in cuY with parameter cuX(the current running instance, i dont have a variable to use). Then i make cuY.RUN which calls a function in cuX(has to be the same intance, from where i started).
    Hope i made myself clear this time. Anybody a clue if this is possible?
  • lubostlubost Member Posts: 627
    Hi,

    if you mark codeunit as SingleInstance=true, NAV will protect this codeunit in memory including all global variables defined in it.
  • SonGoten13SonGoten13 Member Posts: 44
    Yeah, that would be also an option, but i dont want to do that.
Sign In or Register to comment.