AXForum  
Вернуться   AXForum > Microsoft Dynamics NAV > NAV: Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 29.05.2018, 05:43   #1  
Blog bot is offline
Blog bot
Участник
 
20,817 / 715 (65) +++++++
Регистрация: 28.10.2006
waldo: Function Overloading in AL
Источник: https://dynamicsuser.net/nav/b/waldo...rloading-in-al
==============

I haven’t been blogging much, lately. But in my defence – I put quite some time in another community project, which I blogged about in my previous post (and will blog about in quite a few coming posts…). To keep up the pace of writing at least one post each month (which I have been able to do so for the past 11 years or so) – I HAD to put something up urgently ;-). And it’s going to be about a new possibility we have in the AL language, which is often forgotten:

Function Overloading

In C/AL we never had the ability for overloading a function. You know: using the same function name with a different context (parameters).

Now – YES WE CAN! It’s all pretty well described on docs:

https://docs.microsoft.com/en-us/dyn...verload-method

How cool is that?

Can I overload more?

Overloading my own functions is nice. But the question I always get in my classes is: can we also overload functions from the default app – or from any dependent app for that matter.

Well – in short: YES WE CAN!

Let me give you a simple example:



I’m overloading the default method “CreateAndShowNewInvoice” on the vendor table with a different context (Text-parameter). So I have a completely new method, with the same name.

One thing that would be interesting is to be able to extend on a main method like that – and that’s what I basically doing above – I call the main method, and extend it with my own code.
Dependencies

As this works on the default app, you can expect it does work on dependent extensions as well. I created an example on my github, which you can look into.

Extension A implements a new method on the Item table (or should I say “class” ;-)):



Extension B has a dependency on A, and implements a slightly different implementation of that method. You see: same function name, different parameters



To Test the overload, I created a subscriber to logInManagement .. And you’ll see that B basically extended the implementation of A…



And yes, I hear you – One should test with a test-codeunit. So I created that for you as well :-).



And if you’re using the CRS AL Language Extension, it’s easy. Just run the C/AL Test Tool from VSCode from the command palette:



And there you go!



Enjoy!




Источник: https://dynamicsuser.net/nav/b/waldo...rloading-in-al
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
waldo: CRS Al Language Extension Blog bot NAV: Blogs 0 18.04.2018 05:13
waldo: Enable the updated Code Analysis for AL Blog bot NAV: Blogs 0 26.03.2018 08:11
waldo: AL with VSCode: ExportToNewSyntax Blog bot NAV: Blogs 0 07.08.2017 04:17
waldo: Convert C/AL Objects to AL with PowerShell Blog bot NAV: Blogs 0 05.05.2017 03:33
CRM DE LA CREME! Some useful CRMform jscripts Blog bot Dynamics CRM: Blogs 0 02.09.2009 10:05
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 02:32.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.