DEV Community

Peter + AI
Peter + AI

Posted on

πŸš€ Managing Components in Uniface 10.4 with ProcScript: A Simple Guide

This blog post was created with AI assistance based on the official Uniface 10.4 documentation to help developers understand component management better.

πŸ“¦ What is Component-Based Development?

Component-based development in Uniface allows you to create multi-tier applications where different parts of your application can work together seamlessly. Think of components as building blocks - each one has its own specific job, and you can combine them to create complex applications.

Components in Uniface can be services, reports, forms, or server pages. Services, reports, and server pages can exist anywhere in your deployment infrastructure, while forms must run on the system where they are displayed.

πŸ› οΈ ProcScript Commands for Component Management

Uniface provides several powerful ProcScript commands to manage components. Let's explore the most important ones:

Creating Component Instances 🎯

The newinstance command creates a new instance of a component. An instance is like making a copy of a blueprint - you can have multiple instances of the same component running at once.

Basic Example:

newinstance "MyService", "MyServiceInstance"
Enter fullscreen mode Exit fullscreen mode

This creates a new instance of a component called "MyService" and gives it the name "MyServiceInstance".

Activating Operations πŸ”„

The activate command starts an operation on a specified component. This is how you tell a component to do something specific.

Example:

newinstance "CustomerService", "custSvc"
activate "custSvc".getCustomerData()
Enter fullscreen mode Exit fullscreen mode

This creates a customer service instance and then calls the "getCustomerData" operation on it.

Important tip: If you use activate without creating an instance first, Uniface automatically creates one for you!

Deleting Instances πŸ—‘οΈ

The deleteinstance command removes a component instance when you're done with it. This is important for memory management - keeping your application clean and efficient.

Example:

deleteinstance "MyServiceInstance"
Enter fullscreen mode Exit fullscreen mode

πŸ“Š Getting Information About Components

Uniface also provides several functions that return useful information about your components:

Component Name and Type 🏷️

  • $componentname - Returns the name of the component from which an instance was created
  • $componenttype - Returns the type of the component (form, service, report, etc.)

Example:

vComponentName = $componentname("MyServiceInstance")
vType = $componenttype("MyServiceInstance")
Enter fullscreen mode Exit fullscreen mode

Instance Relationships πŸ”—

  • $instancechildren - Returns a list of instances attached to an instance
  • $instanceparent - Returns the name of the parent instance
  • $instancehandle - Returns the handle (reference) of an instance

These functions are helpful when you need to understand the hierarchy of your components - which components are connected to which.

Data Status Checks βœ…

  • $instancedb - Checks if data in the current instance was retrieved from a database
  • $instancemod - Returns the modification status of data in the component
  • $instancedbmod - Returns the modification status of database fields specifically

Example:

if ($instancemod = 1)
    message "Data has been modified!"
endif
Enter fullscreen mode Exit fullscreen mode

🎯 Practical Use Case

Here's a complete example that shows how these commands work together:

; Create a new customer service instance
newinstance "CustomerService", "custSvc"

; Activate the load operation with a customer ID
activate "custSvc".loadCustomer(12345)

; Check if data was loaded from database
if ($instancedb("custSvc") = 1)
    ; Process the customer data
    activate "custSvc".processCustomer()
endif

; Clean up - delete the instance when done
deleteinstance "custSvc"
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Key Takeaways

Component management in Uniface 10.4 gives you powerful tools to:

  • Create and manage multiple instances of components dynamically
  • Activate operations on specific component instances
  • Track relationships between components
  • Monitor data status and modifications
  • Clean up resources properly for better performance

Understanding these ProcScript commands is essential for building scalable and maintainable Uniface applications. Start with simple examples and gradually build more complex component interactions as you become comfortable with these concepts.

Happy coding! πŸŽ‰

Top comments (0)