Avoid validation errors when updating programs and routines in the Code Editor

When updating programs and routines in the Code Editor, validation errors occur because of missing or duplicate implementations or forward declares.
In
FactoryTalk® Design Studio™
, an implementation is the actual definition of the program or routine, including its properties, tags, and content.
Example of an implementation
Implementation example
A forward declaration signifies that an element exists, but its implementation resides in a different location, most often in another file. For example, a forward declaration of a routine informs the parent program that it contains a routine, but the routine implementation is in another file. Forward declarations are indicated by placing the keyword
extern
in front of the declaration's signature. The signature includes the name and sets of parameters (order, names, types, and usage). This approach helps in organizing code into separate files, keeping them small, and allowing implementations to be more easily managed when performing Version Control System merges and potential merge conflicts.
Example of a forward declare
Forward declare example
Examples of a forward declare and program and routine implementations
Examples of a forward declare and program and routine implementations
To avoid introducing validation errors into the code, follow these guidelines:
  • Editing the name of a program or routine
    :
    • When editing the name of a program or routine, change both the forward declare and the implementation.
    • Edit the name in the
      Properties
      panel instead of using the Code Editor. If you edit the name in the
      Properties
      panel, the system will update the name in both the forward declare and the implementation.
    • To edit the name in the Code Editor, right-click the component and select
      Open Code Editor
      to change the name in the implementation. Then right-click the parent container and select
      Open Code Editor
      to change the name on the line with the external declare.
      TIP: Changing the name of an element in the Code Editor only updates the text, not all references. Use the Properties panel to ensure both forward declares and implementations are updated.
  • Deleting a program or routine
    :
    • When deleting a program or routine, delete both the forward declare and the implementation.
    • Instead of using the Code Editor, if you delete the program or routine by right-clicking the component in the Explorer and selecting
      Delete
      , the system deletes both the forward declare and the implementation.
    • To delete the program or routine in the Code Editor, right-click the component and select
      Open Code Editor
      to delete the implementation. Then right-click the parent container and select
      Open Code Editor
      to delete the external declare.
      TIP: Deleting through the explorer panel ensures all associated files and directories are removed. Avoid deleting by text in the Code Editor, as it does not clean up implementation files
  • Creating a program or routine
    :
    • When creating a program or routine, create both the forward declare and the implementation.
    • Instead of using the Code Editor, if you create the program or routine by right-clicking the parent component in the Explorer and select
      New program
      or
      New routine
      , the system creates both the forward declare and the implementation.
    • If you create the component as an inline component instead of using the keyword, see Inline and external routines for guidance.
    • When creating these components in the Code Editor, verify that the name is unique.
  • If validation errors occur, double-click the error in
    Output
    to navigate to the error in
    FactoryTalk Design Studio
    .
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal