Home AMX User Forum NetLinx Studio
Options

question about axi files

Hello Everybody,

Writing include axi files in different places may have different outcomes and sometimes compilation error.

Where should I put the include axi files in my program? any rules?

As there may have variables, constant, define call,etc inside different axi files, how the compiler handle them?

Thanks in advance for any inputs.

Cheers
Charles

Comments

  • Options
    DHawthorneDHawthorne Posts: 4,584
    If you put the appropriate DEFINE_* header in them, you can #INCLUDE them right at the top of your source, before the DEFINE_DEVICE section. That makes it easier to see what you have and update them when needed. If they only have constants in the, you can put it in the DEFINE_CONSTANT section, etc., but the most important thing to remember is you can't use any of the values or CALLs you define in one in any point of your code before the #INCLUDE line.
  • Options
    Originally posted by DHawthorne
    but the most important thing to remember is you can't use any of the values or CALLs you define in one in any point of your code before the #INCLUDE line.

    Exact, but FUNCTIONS will be found wherever they are included...

    Typically the problem with include files is the order of inclusion depending on the cross-references between them. It is easier if one creates either:
    - "type" axi, that is, an axi that contains some constants, a struct and functions that act on the struct (with proper DEFINE_XXX). For example I have such an include for a DateTime_Type, with functions like DateTime_now, DateTime_AddSeconds, DateTime_AddWeeks, etc...
    This type of include files goes to the top of the code, since they do not reference any variable or device (they are self contained, you can actually COMPILE them successfully on their own). In the code, you use variables of said type.

    - "section" axi, that is, an axi that contains all of the device event handlers for a touch panel, or all of your constants, etc (this is the approach AMX used in DXP-HT 1.0 I think). You include these axi in the relevant section of your code.

    Once you start mixing up things, it quickly gets complicated and you may need to break up files to make them compile without too much headaches.

    Hope this helps

    Fred
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    DHawthorne writes:
    ...the most important thing to remember is you can't use any of the values or CALLs you define in one in any point of your code before the #INCLUDE line.

    I disagree. A DEFINE_CALL can be placed in the .axs file or in any include file and the .axs file or any include file can call that call regardless of where the includes are included or in what order the includes are included or in what order the calls are defined.

    If there is a variable in a program that is not in scope due to the order or placement of the includes then one option is to write a DEFINE_CALL in the include that is in question to get or set the value of that variable.
  • Options
    DHawthorneDHawthorne Posts: 4,584
    Originally posted by Joe Hebert
    I disagree. A DEFINE_CALL can be placed in the .axs file or in any include file and the .axs file or any include file can call that call regardless of where the includes are included or in what order the includes are included or in what order the calls are defined.

    If there is a variable in a program that is not in scope due to the order or placement of the includes then one option is to write a DEFINE_CALL in the include that is in question to get or set the value of that variable.
    I wasn't entirely clear; I was not referring to DEFINE_CALL nor DEFINE_FUNCTION, but the DEFINE_*'s that indicate section headers. calls and functions aren't true program segments, you can put them anywhere as long as they are defined before they are called.
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    DHawthorne writes:
    ...calls and functions aren't true program segments, you can put them anywhere as long as they are defined before they are called

    That's the part I respectfully disagree with. You don't need to define them before they are called. All you need to do is define them, period, end of story.

    For example, if you define DEFINE_CALL #1 and DEFINE_CALL #1 calls DEFINE_CALL #2 and DEFINE_CALL #2 is defined after DEFINE_CALL #1, the code will compile and run just fine. How much wood can a wood chuck chuck....
  • Options
    I confirm. In NetLinx, calls and functions do not need to be defined before being used, but everything else does.

    Fred

    [Edited to add the NetLinx precision, never done Axcess so can't comment]
  • Options
    DHawthorneDHawthorne Posts: 4,584
    Well I've learned something then. It was certainly the case in Axcess, I have many times gotten the error message that a call was not defined simply because of its placement. I just assumed it carried over to NetLinx.

    Thanks for the correction. :)
  • Options
    It's my understanding that the "DEFINE_CALL placement not being important" is just quirk, not something that explicitely designed into the language.

    Other than that, I agree with DHawthorne - to be safe, always declare your sections in Netlinx include files, AND you should also have one after the #INCLUDE line just in case the include changes to a different section than the one it's declared in. (Of course, if it's the last thing in your code this will not be necessary.)

    Also, don't ever put a } or ; on the #INCLUDE line, these can cause problems...

    Finally, I also prefer putting includes at the top of code, but once you understand the other rules it's really a matter of personal preference.
Sign In or Register to comment.