Code and Data: Private or Public
In visual
projects all
constants and data for each Window,
MDIWindow
or DialogBox
objects are private, that is, only accessible to the own object and its
children. To share data
with other objects in the project, you can add Include
files or Module
objects. Modules
are code objects, which means that they have no window and cannot
contain controls, but all variables and procedures inside them are
Public
by default, that is,
common to the whole project. This can NOT be
applied to
macros nor structures, which are
only available in the
Window or Module where they are
defined (unless you
define them in an include file as explained below).
Include files
may also be common to the whole project if they are added in the right
way. If you want an Include file to be common to
the whole
project, do the following:
For MASM32 SDK
or a driver programming include files, use the
"Project=>Add Include files (*.inc)..."
menu option
When added that way, include
files are always included in all other files in the project
(windows and modules) when compiled, so they cannot have
procedures nor variable
declarations, otherwise redefinition errors will be fired
(good examples of include files are those coming
with
the MASM32 SDK). On the other hand, include
files are very useful for defining macros and/or structures
being common to the whole project (i.e. the Common.inc
file
of the NetMon project, in the Examples
folder).
For any other type of include files,
use the "Project=>Add Files..."
menu
option (if the file is not in the project folder, it will be
copied to)
Module objects are Easy Code defined and they must
be properly structured in order to avoid programming errors. For modules
to work fine, a very important rule must be taken into account:
The .Const,
.Data?
and .Data
sections, must
ALWAYS be coded before the .Code
section like this:
A module can be very useful for containing
variables
and procedures being referenced by any other object (window
or module), since all its variables and procedures are common
to the whole project. However, if you want the data in a
module to be private, just do the following:
.Const
In fact, the order of .Const,
.Data?
and .Data
sections does not
matter, the important thing is that just one .Code
section is allowed in a module
and it has to be the last of all sections.
.Data?
.Data
.Code
For visual projects:
Set the PublicData property to FALSE
For classic projects:
Uncheck the Make all variables global option in the Project properties
For Window,
MDIWindow
and DialogBox
objects, Easy
Code declares procedures as Private
by default, while in Module
objects they are declared as Public.
As Easy Code ignores the Option
Proc
directive, all procedures are Public,
if not explicitly declared as Private,
so that they may be accessed
by any other object in the project. In fact, all procedures are Public
by
default if neither, Private
nor Public
are declared, so the following procedures are exactly the same:
AnyName Proc
Ret
AnyName EndP
and
AnyName Proc Public
Ret
AnyName EndP
If you want a procedure to be private, just add the corresponding
reserved word
(Private),
and the procedure will only be accessible inside the object where
it is coded:
AnyName Proc Private
Ret
AnyName EndP
So, if you set the PublicData property to FALSE (visual projects), or unckeck the Make all variables global option (classic projects), and all its procedures are declared as Private, you will get a private module, that is, only accessible inside the own module. On the other hand, setting the PublicData property to TRUE (visual projects), or checking the Make all variables global option (classic projects), and not declaring as Private any of its procedures, will result in a public module, where data and code will be accessible from any other object in the project.
It is a good practice to keep Private all procedures inside a window object (visual projects) and adding one or more Include files (or Modules) for common code and data. Your code will be clearer in that way, looking like higher level languages, and less exposed to errors. So Easy Code works when writing code for a procedure: all procedures inside a window object are declared Private (unless you make them Public), while all procedures inside a module object are declared Public (unless you make them explicitly Private). In fact, Easy Code does not write neither, Public nor Private, which means Public.
REMARKS: Easy Code takes care of the prototypes for all existing procedures in the project. So, you DO NOT NEED to write nor to include any Proto sentence, as they are not needed in Easy Code projects.
IMPORTANT:
Remember that Easy Code ignores the Option
Proc
directive, so for a procedure
to be private, just add the corresponding
reserved word (Private).
If neither, Public
or Private
are declared, the procedure will be considered as Public
.