Can you please clarify what is the meaning of "codeunit instance"? What is single instance and multi instance codeunit? It would be great if the guidelines are supported with examples. :!:
If I have two variables of type Codeunit 80 (for example...)
SalesPost.Blablabla;
SalesPost2.Blablabla;
I have two instances of the codeunit 80. If the function Blablabla works with global variables in the codeunit, the change through variable SalesPost will not be visible in SalesPost2 (there are two objects in memory, two separate memory area for each INSTANCE).
But if I set the property SingleInstance = Yes, both variables will work with same instance of the codeunit, all global variables in the codeunit will be shared through all variables of type Codeunit 80.
OK let's put it in some other way: probably the only time you'd use a singleinstance CU is whenever you write some interface routine that runs continuously and waits for data to appear for it to pick up on the disk or in an MSMQ queue etc.
Or because you want to optimize setup table readings (read once per client run), or you need to pass parameters between objects - in cases when you need "shared" memory space which can be used for communication... 8)
Hi All
Codeunit has two type of instances. i don't know the Practical use of codeunit single instance and multiple instance. If anyone explain with examples, it will be very understandable to me...... O:)
Dream is not the thing, what you see in the sleep. Dream is the thing, which does not let you sleep.
This is the problem, if somebody does not know the basic OOP theory it becomes rather difficult to explain. This is a NAV forum not an OOP one.
A single instance codeunit is basically one that can only exist as a single object. Once the object is created, it stays in memory until it is killed by closing of the company. Any new creations of this codeunit will not actually create a new object, but rather refer directly to the one that currently exists. All of its internal global variables and their states are kept over all references to the object.
A multiple instance codeunit is exactly what it says on the tin. Every new creation of the codeunit creates a new object that has its own set of variables in their own state. It is also deleted when it goes out of scope.
Comments
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
If I have two variables of type Codeunit 80 (for example...)
I have two instances of the codeunit 80. If the function Blablabla works with global variables in the codeunit, the change through variable SalesPost will not be visible in SalesPost2 (there are two objects in memory, two separate memory area for each INSTANCE).
But if I set the property SingleInstance = Yes, both variables will work with same instance of the codeunit, all global variables in the codeunit will be shared through all variables of type Codeunit 80.
"Multi instance":
SalesPost --- CU80
SalesPost2 --- CU80
"Single instance":
SalesPost --- CU80
SalesPost2 --/
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Codeunit has two type of instances. i don't know the Practical use of codeunit single instance and multiple instance. If anyone explain with examples, it will be very understandable to me...... O:)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
A single instance codeunit is basically one that can only exist as a single object. Once the object is created, it stays in memory until it is killed by closing of the company. Any new creations of this codeunit will not actually create a new object, but rather refer directly to the one that currently exists. All of its internal global variables and their states are kept over all references to the object.
A multiple instance codeunit is exactly what it says on the tin. Every new creation of the codeunit creates a new object that has its own set of variables in their own state. It is also deleted when it goes out of scope.