Optional parameters in functions

TbiTbi Member Posts: 33
edited 2004-09-22 in Navision Attain
Hi

I'm writing some codeunits, and tries to find out how to make a function with optional parameter(s).
Is this possible, and if, how?

Comments

  • kinekine Member Posts: 12,562
    I think, that it is no possible to have function with variable count of parameters. No way how to do that. No way to set default value for some parameter, no way how to define more functions with same name but another parameter count.

    But> one place where are functions with variable count of parameters exist> automations.... if you look to some code with automations, there are used many functions with default parameters...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • PEzechielsPEzechiels Member Posts: 83
    example:
    define the following variables:

    Name Type
    ParameterInput Dialog
    Parameter1 Integer
    Parameter2 Integer
    Parameter3 Integer

    Text Constant:
    Name ConstValue
    Text1000000003 Please Specify the parameters\Parameter1 #1#######\Parameter2 #2#######\Parameter3 #3#######

    On top of your script place this code

    ParameterInput.OPEN(Text1000000003)
    ParameterInput.INPUT(1,Parameter1);
    ParameterInput.INPUT(2,Parameter2);
    ParameterInput.INPUT(3,Parameter3);
    ParameterInput.CLOSE;


    and then ofcourse the usual
    Rec.setfilter(field1,parameter1);
    Rec.setfilter(field2,Parameter2);
    Rec.setfilter(field3,Parameter3);
    etc etc.
    and now you have your parameters.
    If you want the window to open optionally you should place a condition before executing the above script;

    Hope this helps
  • TbiTbi Member Posts: 33
    Thanks.
    I cannot use dialog (i shall use this codeunit within NAS so userinput is impossible). Optional parameters would have been 'nice to have', but I will find a way around..

    - T.
  • kinekine Member Posts: 12,562
    One way around is array of variant type variable and count of params in array passed into function... but no automatic type control etc...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • PolarPolar Member Posts: 32
    what's a problem?

    Function(Param1,...,Var OptionParameter:option);

    and return value into OptionParameter.
    keep it simple
  • kinekine Member Posts: 12,562
    Polar wrote:
    what's a problem?

    Function(Param1,...,Var OptionParameter:option);

    and return value into OptionParameter.
    Problem is how to create function with same name with possibility to fill only some parameters (something as default parameters in C etc.)
    Definition:
    Function F(Param1,Param2,Param3);
    
    have possibility to call as:
    
    F(p1);
    F(p1,p2);
    F(p1,p2,p3);
    

    something as calling MESSAGE(Text000), or MESSAGE(Text000,P1) etc...
    [/code]
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • PolarPolar Member Posts: 32
    kine, have you already solved a problem?

    Unfortunatly, Navision is not object-oriented programming , but only based on it. :? :(
    keep it simple
  • dufourdufour Member Posts: 9
    A working solution, but, it's .. not the best

    Create a table, the fields are possible parameters (so you can have corrcet format)
    On this table, you set a unique ID for each row.
    When you call your function, you write the rox with your parameters, and give the unique ID to your function.
    Your function retrieve row parameters (with ID) and work

    ...

    I think it's the "best" solution with Navision
  • PolarPolar Member Posts: 32
    I do love Navision,
    Where with little exertion
    And with extra-vision
    You find through-ass solution.
    :lol: :P :):o:wink:
    keep it simple
Sign In or Register to comment.