To VAR or to DAT ?
Nico S
Posts: 9
Hi all,
I have read the VAR and DAT block designator section in manual ver 1.1.
The VAR block designator gives a clear description of the object and cog scope on declared variables.
Im a bit confused on when to declare/use a variable(s) in the DAT or VAR block.
Are there differences in scope between the VAR and DAT block ?
Sorry if this has been asked before.
TIA,
Nico Schoemaker.
I have read the VAR and DAT block designator section in manual ver 1.1.
The VAR block designator gives a clear description of the object and cog scope on declared variables.
Im a bit confused on when to declare/use a variable(s) in the DAT or VAR block.
Are there differences in scope between the VAR and DAT block ?
Sorry if this has been asked before.
TIA,
Nico Schoemaker.
Comments
The main difference is that each instance of the object declared somewhere else has its own VAR area. The DAT blocks are grouped together and allocated only once no matter how many instances of the object there may be.
Lets say you have an I/O driver that provides access to PC-compatible files on an SD card. Lets say you want to have several files open. You would put any variables that are common to all files into a DAT block. This might include the volume name and maybe some information about the volume directory. Each file would be handled by a separate instance of this object. The variables that have to do with a specific file would be declared in a VAR block. Each declared instance would have its own copy of the file variables. There would be only one copy of the volume related variables and only one copy of the code itself.
Thank you, your anwser was very helpful.
So VAR declared variables can be·seen as·object/instance variables and DAT declared variables·as class/static variables.
In other words VAR declared variables are private to an instance of a class and DAT declared variables are shared among every instance of the class.
Best regards,
Nico Schoemaker.
-Phil