βΉοΈ 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
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
π² 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
π·οΈ 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
β οΈ 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 ofx
) π - 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)