DEV Community

Peter + AI
Peter + AI

Posted on

🚀 Understanding Component Variables in Uniface 10.4

â„šī¸ This blog post was created with AI assistance to help explain Uniface concepts in simple terms.

đŸ“Ļ What Are Component Variables?

Component variables are temporary storage areas in your Uniface component. Think of them as containers where you can store data temporarily while your component is running. They work like boxes where you can put information and retrieve it later within the same component.

The key thing to remember: these variables are only available within the component where you define them. They live and die with that component instance. đŸ’Ģ

đŸŽ¯ When Should You Use Component Variables?

Component variables are perfect for several situations:

  • Running Totals 📊 - Store intermediate results from calculations before showing them in a field
  • Status Flags 🚩 - Keep track of whether something has happened or not
  • Temporary Counters đŸ”ĸ - Count things during the component session
  • Print Data Transfer đŸ–¨ī¸ - Move data into break, header, and footer frames when printing

âœī¸ How to Define Component Variables

Defining a component variable is straightforward. You declare it in a variables block inside the Declarations container of your component.

📝 Example 1: Basic Variable Declaration

; Declarations container of component
variables 
  string vString
  numeric DIS(999P99) myNumber
endvariables
Enter fullscreen mode Exit fullscreen mode

In this example:

  • vString is a string variable (for text) 📝
  • myNumber is a numeric variable with specific formatting (up to 999 digits before decimal, 2 after) đŸ”ĸ

🔍 How to Use Component Variables

To reference your component variables in ProcScript, wrap the variable name with dollar signs: $VariableName$

💡 Example 2: Using a Variable in Code

if ($myNumber$ <= 123)
  ; do something when number is less than or equal to 123
  message "Number is small!"
endif
Enter fullscreen mode Exit fullscreen mode

🎲 Example 3: Counter Variable

; Declarations
variables 
  numeric counter
endvariables

; In your ProcScript
$counter$ = 0
while ($counter$ < 10)
  ; perform some action 10 times
  $counter$ = $counter$ + 1
endwhile
Enter fullscreen mode Exit fullscreen mode

đŸˇī¸ Example 4: Status Flag

; Declarations
variables 
  string dataLoaded
endvariables

; In your ProcScript
if ($dataLoaded$ = "YES")
  message "Data already loaded!"
else
  ; load the data
  $dataLoaded$ = "YES"
endif
Enter fullscreen mode Exit fullscreen mode

âš ī¸ Important Limitations

Remember these key points when working with component variables:

  • 🔒 Component-Specific - Variables only work within the component where they're defined
  • 🔄 Data Transfer - To move data between components, use operation parameters or global variables instead
  • âŗ Temporary Storage - These variables don't persist after the component closes

🎓 Best Practices

  • Use clear, descriptive names for your variables (like orderTotal instead of x) 📛
  • Declare all variables at the beginning in the Declarations container 📋
  • Initialize your variables before using them đŸŽŦ
  • Use appropriate data types (string for text, numeric for numbers) đŸŽ¯

🎉 Conclusion

Component variables in Uniface 10.4 are simple but powerful tools for managing temporary data within your components. They help you write cleaner code by providing a clear place to store intermediate values, status flags, and counters. Just remember they're component-specific and temporary!

Happy coding! 👨‍đŸ’ģ👩‍đŸ’ģ

Top comments (0)