I have defined a Procedure in C/AL (Navision Attain 3.10) as follows :
SomeProcedure(SomeParameter : 'OptionA,OptionB')
For the type of SomeParameter I chose Option and then with the properties I defined the Optionstring OptionA,OptionB.
Inside my procedure I can use SomeParameter::OptionA and SomeParameter::OptionB.
The problem comes however when I try to call this procedure from somewhere else.
SomeProcedure(0); does work, but it somewhat beats the target of defining the Optionstring in order to make the code more readable.
Is there some way of using the defined values OptionA or OptionB when calling this procedure ?
Thanks,
Jens
0
Comments
To make your code more readable i would call the procedure as Someprocedure(Option::A) and it would make more sense than saying Someprocedure(0);
Thanks
Best regards
Suresh.
NY.
sample:
Ok, it's a sample so please son't ask me what's the use of the code I just typed.
* Code not tested.
If it was hard to write, it should be hard to understand."
The problem is that when you define an Option as a parameter, there is nothing that can act as a type name.
OptionA and OptionB are the possible values for a variable of type Option, but the only way to reference them is inside the procedure as SomeParameter::OptionA. That this does not work outisde the procedure is logical because the scope of SomeParameter is limited to the procedure itself.
In reply to Emiel Romein.
The reason that I want to do this is because Navision does not know overloading.
Let's extend SomeProcedure to
SomeProcedure(SomeCodeType : 'CodeTypeA,CodeTypeB', SomeCode : Code 10)
In a OO language I would simply strong type SomeCode and provide two overloads, something like this :
Type CodeTypeA : Code 10;
Type CodeTypeB : Code 10;
SomeProcedure(SomeCode : CodeTypeA)
SomeProcedure(SomeCode : CodeTypeB)
Now the compiler would to the job. Unfortunately, C/AL does not seem to know overloading, so I just try to simulate that by supplying an OptionString value to indicate which type of Code I pass in.
Saying that I shouldn't do this does nto help me.
And looking at standard Navision does not help me either, I find the quality of the code of standard Navision below average. I like to try to do better, I like to compensate for the lack of power of the language and the develoment environment. Telling me that I should not do that does not help at all...
Regards,
Jens Samson
You should not do that!
Just kidden', but don't put to much time and effort in it. Standard Navision isn't as bad as you think it is. The only reason you feel the why you feel is course you know much better languages to program in. You just have to except Navision as it is. Which is not a develop language, but a ERP application with GREAT flexibility. If you look at Navision this way, it is one of the best products on the market.
And trust me, don't try to improve the way Navision developers programs. It's a good balance of needed statements and readable code.
But to get back to the non-overload sample.
I'm not telling you to not use options in your function, but I'm telling you to replace options by integers.
if you define "Func(foo : Option, bar : code 10)" you will have to call this function with a option var. So this will be:
VAR foocall : Option;
foocall := foocall::foo;
Func(foocall, barcall);
You have to define a new var. foocall which is a bit unnecessary. Instead it's much better to make the parameter foo a integer. This way you can call it without the creation on a new var. Just comment the option to make it clear.
func(0, barcall); // 0 = foo
Another (not beautiful) solution could be filling global vars which you can use in your function.
Globalfoo := foo;
Glabalbar := bar;
Func();
Function func();
Begin
Message(strsubstno(‘%1 %2’,globalfoo,globalbar));
End
If it was hard to write, it should be hard to understand."