π This blog post was created with AI assistance to help developers understand Uniface component construction better.
Hey developers! π If you're working with Uniface 10.4, understanding how to construct components is essential. Components are the building blocks of your application, whether you're building desktop apps, web applications, or mobile apps. Let me walk you through the process in simple terms!
π― What is a Uniface Component?
Think of a component as a reusable piece of your application. It can be a form that users interact with, a service that handles business logic, or a server page for web applications. Each component has its own data structure and behavior that you define.
π Before You Start
Before constructing a component, make sure you have:
- A project to contain your application definitions
- Modeled entities defined if your component will access database data
What are modeled entities? These are abstract objects that represent database tables or other data structures. They define what data your application can access and how it behaves.
π οΈ The Step-by-Step Process
Step 1: Create a New Component π
Uniface offers different component types for different purposes:
- Forms - For desktop applications with user interfaces
- Server Pages - For web applications and mobile apps
- Services - For business logic in all applications
- Session Services - For data access in multi-tier applications
Example: If you're building a customer management screen for a desktop app, you would create a form component. For a web-based customer portal, you'd create a server page component.
Step 2: Define the Component Structure π
The component structure controls:
- What data the component uses (entities and fields)
- The order in which data is processed
- Default behavior when data is stored or deleted
Most component entities are created by inserting modeled entities. You can also create non-database entities that are specific to just this component.
Example: For a customer order form, you might insert the modeled entity "CUSTOMER" and "ORDER". These inherit all the properties and behavior defined in the model, but you can customize them for this specific component.
Step 3: Script the Component Behavior π»
This is where you write ProcScript (Uniface's scripting language) to control component-specific behavior. Script modules define what happens when users interact with your component or when data changes.
Example ProcScript:
trigger apStart ; This runs when the component starts message "Welcome to the Customer Form!" end ; apStart trigger CUSTOMER.validate ; This validates customer data before saving if (CUSTOMER.EMAIL = "") message "Email address is required!" return -1 endif end ; validate
Step 4: Create the Component Layout π¨
For presentation components, you design how the component looks and where fields appear:
- Forms use the Uniface form designer with visual controls
- Server Pages use HTML for layout design
Example for Server Pages: You would create an HTML layout that includes Uniface-specific tags to display your component data in a web browser.
Step 5: Compile Your Component βοΈ
Click the Compile button to compile your component. This converts your component definition into executable code that Uniface can run.
Why compile? Compilation checks for errors and creates the runtime version of your component. If there are problems in your structure or script, the compiler will tell you.
Step 6: Test Your Component β
From the Actions menu, choose Test. This spawns a separate process and activates the exec operation of your component. When testing is complete, control returns to the Uniface IDE.
Testing Tip: You can customize the test environment using test logicals in the ide.asn file. This lets you provide command line switches that override default behavior.
π Working with Global Objects
After creating your component, you might need to create libraries of global objects that components can access, such as:
- Messages that appear across multiple components
- Global variables used throughout the application
- Global ProcScript functions for shared functionality
Example: If you have a standard error message that appears in many components, define it as a global message once instead of typing it in every component.
π Key Concepts to Remember
Component Entities vs. Modeled Entities:
- Modeled entities are abstract templates defined once
- Component entities are concrete instances derived from modeled entities
- Component entities inherit from modeled entities but can be customized
Component Types for Different Tiers:
- Presentation tier: Forms and Server Pages
- Business logic tier: Services
- Data access tier: Session Services
π‘ Common Pitfalls to Avoid
- Forgetting to define modeled entities first: If your component needs database access, you must have modeled entities defined before creating the component
- Not compiling after changes: Always compile your component after making changes to see errors and create the executable version
- Skipping the test phase: Testing in the IDE helps catch issues before deployment
- Mixing concerns: Use the right component type for the right job - don't try to put business logic in forms when it belongs in services
π Wrapping Up
Constructing components in Uniface 10.4 follows a logical workflow: create, define, script, design, compile, and test. Once you understand this pattern, you can quickly build robust components for any type of application. The key is understanding the separation between modeled entities (your data model) and component entities (how components use that data).
Start simple, test often, and gradually add complexity as you become more comfortable with the process. Happy coding! π
Top comments (0)