Calling a function as parameter

I have 3 functions on a table Table1 - Func1, Func2 and Func3. Is it possible to create another function called with a parameter indicating which function on Table1 to run?? That is, a function FuncCallFunction in say a codeunit, called with a parameter FuncParam (text) - now defining Table1 as a variable in this function I will make this call: Table1AsVariabel.FuncParam; In our version (3.70 with 3.01b objects) I can’t make it work…

What do you mean exactly? You can run a function in a table from any other navision object as long as you define the table as variable. Have you checked the local parameter of the function? If this is set to true the function is not available outside the object.

If I understand you well, I think you have to make the following call: Table1AsVariabel.FuncCallFunction(FuncParam);

So to elaborate a little… Make your Func1, Func2 and Func3 local procedures, so you can’t call them from other objects (this of course is only necessary if you don’t want that to happen, you can also leave the global procedures, nothing wrong with that). Then, you add another function called “CallMyFunction” or whatever else works for you. Give it a parameter like an integer or something, as long as you document what the integer values mean, and call it “parIntegerValue”. Then inside the new function you write a CASE structure to handle the actual function calls: CASE parIntegerValue OF 1: // call func1 BEGIN Func1(); END; 2: // call func2 BEGIN Func2(); END; 3: // call func3 BEGIN FUNC3(); END; ELSE BEGIN ERROR(‘Unknown Integer Value’); END; END; Does that make sense?

I am sorry that looks like crap, but for some reason it does not allow spaces at the start of a new line. By the way, why do you have to do it like this? If you have the object as a variable anyway, you can simply call the right function to begin with.


So to elaborate a little… Make your Func1, …
Originally posted by DenSter - 2005 Dec 13 : 17:10:06

Daniel, put you code inside code tags, and it will look like this. >>> the markers are [ code ] … [ /code ] (without the spaces) [:)] CASE parIntegerValue OF 1: // call func1 BEGIN Func1(); END; 2: // call func2 BEGIN Func2(); END; 3: // call func3 BEGIN FUNC3(); END; ELSE BEGIN ERROR('Unknown Integer Value'); END; END;

Thanks David, I know about the code tags, I just don’t like the stupid scrollbox. I want to be able to see all the code, so I always use a different font to make it look different.

the advantage of the scroll ox, is you can easily copy paste the code straight into Navision. Admittedly though the scroll box needs to be bigger.

It should work the same as the quote box, except with Courier New or any other monotype as the font.

Well, back to the original topic[^] Daniel - your Case-solution would work but not quite do the trick… The question has come up, because I may want to use the Job Scheduler Setup i Navision with some extension. In the standard version you only have the possibility of running a Report, Dataport or a Codeunit. But I have several functions (on tables and Codeunits) that I want to run. I could create several new codeunits with one function in each of them, but it would be nice if I instead could choose ‘Object Type’ = Table and then have acces to all function on that table. Does this make any sense?? Jens

Basically the answer is yes, this is possible. And now the bad thing around it: You need to read the binary code of the object (from the BLOB field of the object table) and analyze it to find the functions in it. Then you need a codeunit which you can stream into (also binary). So basically you need to generate a compiled Navision object from C/AL. This is very hard to achieve, but it is possible. I did something similar to call different kinds of objects (reports, codeunits, forms, dataports) with a RecRef instead of a Record. Your story is much more difficult than my one was.

Well, then my solution will be that of creating one codeunit pr. function I want to call!!