Hi, How can you create a codeunit (table independant). The codeunit must have some parameters ( f.e. a few string) en gives an return value. I want to call that codeunit from a Form. The question is: What is the syntax for calling that codeunit with parameters. Thankx B.
Hello; You can create a codeunit in the object designer the same way you would create a new table or form. Once you have done this, open the new codeunit in design mode. Alternatively, you could just open an existing codeunit. To add a procedure, select View → Globals. Choose the “Functions” tab and then put the name of your new procedure on the first available blank line. Once the procedure is defined here, its characteristics can be set by pressing the “Locals” button on the right of the procedure list. The form that appears when you press “Locals” allows the definition of parameters, return values and variables/constants local to the procedure. It sounds like you are trying to keep your string-handling procedures in one place, where a number of objects can access them. Brian.
quote:
Originally posted by bartwyckmans: Hi, How can you create a codeunit (table independant). The codeunit must have some parameters ( f.e. a few string) en gives an return value. I want to call that codeunit from a Form. The question is: What is the syntax for calling that codeunit with parameters. Thankx B.
Open a new codeunit, go to the global variables and select the functions tab. Add a new function with the parameters and return values you want. Now put your code in the new function and save the codeunit. On your form, declare a new variable (either local in the trigger/function where you want to call the codeunit or global if you want to get to it from a number of places) with type codeunit. Now you can call the function in the codeunit from code with parameters and get the return variable. That’s the easy way. Alternatively, if you really, really want to use Codeunit.RUN then you can do it the hard way. Add two new functions to your codeunit. For example, I will call them SetParameters & GetResult. Now setup global variables for all the parameters and the return value. Put code in the SetParameters function to pass the function parameters to the equivalent globals and in the GetResult to pass the global back to the return value. Put your processing code in the OnRun function of the codeunit using the global variables. Now, from your form, you call the SetParameters function (which sets up the globals in the codeunit), RUN the codeunit (which uses the globals) and finally call the GetResult function (which passes the global back via the return varaible). Phew! Told you it was the hard way! Cheers, John