How to use a structure as a global variable for intermodule communication?
[Deleted User]
Posts: 0
Hi everybody,
I have a program which consists of a Main file and two modules. In the main file the following structure is declared:
DEFINE_TYPE
STRUCTURE MyStruct
{ LONG Num;
CHAR Name[30];
}
DEFINE_VARIABLE
MyStruct Var_struct;
DEFINE_MODULE 'FirstModule' FirstModule(Var_struct);
DEFINE_MODULE 'SecondModule' SecondModule(Var_struct);
I want it to be visible in both modules. In order to do that I defined the structure in the DEFINE_TYPE section in the modules and declared the MyStruct Var_struct in the formal argument list of both modules. It looks like this:
// Excerpt from the First Module
MODULE_NAME='FirstModule' FirstModule(MyStruct Var_struct);
DEFINE_TYPE
STRUCTURE MyStruct
{ LONG Num;
CHAR Name[30];
}
// Excerpt from the Second Module
MODULE_NAME='SecondModule' SecondModule(MyStruct Var_struct);
DEFINE_TYPE
STRUCTURE MyStruct
{ LONG Num;
CHAR Name[30];
}
But the compiler failed to compile the modules. Apparently it started parsing from the top of each module. By that moment the structure was undefined. So is it possible to use structures as a global variable for intermodule communication?
Your insights are appreciated.
Thanks in advance,
Paul,
Seior programmer,
Disystems,
Yekaterinburg,
Russia
I have a program which consists of a Main file and two modules. In the main file the following structure is declared:
DEFINE_TYPE
STRUCTURE MyStruct
{ LONG Num;
CHAR Name[30];
}
DEFINE_VARIABLE
MyStruct Var_struct;
DEFINE_MODULE 'FirstModule' FirstModule(Var_struct);
DEFINE_MODULE 'SecondModule' SecondModule(Var_struct);
I want it to be visible in both modules. In order to do that I defined the structure in the DEFINE_TYPE section in the modules and declared the MyStruct Var_struct in the formal argument list of both modules. It looks like this:
// Excerpt from the First Module
MODULE_NAME='FirstModule' FirstModule(MyStruct Var_struct);
DEFINE_TYPE
STRUCTURE MyStruct
{ LONG Num;
CHAR Name[30];
}
// Excerpt from the Second Module
MODULE_NAME='SecondModule' SecondModule(MyStruct Var_struct);
DEFINE_TYPE
STRUCTURE MyStruct
{ LONG Num;
CHAR Name[30];
}
But the compiler failed to compile the modules. Apparently it started parsing from the top of each module. By that moment the structure was undefined. So is it possible to use structures as a global variable for intermodule communication?
Your insights are appreciated.
Thanks in advance,
Paul,
Seior programmer,
Disystems,
Yekaterinburg,
Russia
0
Comments
The only way to do something similar is to convert the structure with VARIABLE_TO_XML() or VARIABLE_TO_STRING() into a variable, pass the variable's content out of the module and into the next module, where it can be converted back with XML_TO_VARIABLE() / STRING_TO_VARIABLE().
I've taken to trying to reduce all my inter-module communications to something that can be encapsulated in a virtual device using levels and channels, then using said virtual for a command interface (send_commands) for everything else. In most cases, passing a structure, or its contents, has not been necessary ...but it sure would be convenient if we could.