β οΈ This blog post was created with AI assistance
π‘ What is a Component Instance?
A component instance is simply a running version of your Uniface component. Think of it like this: if a component is a recipe, then a component instance is the actual cake you bake from that recipe. You can bake multiple cakes from the same recipe, just like you can have multiple instances of the same component running at the same time! π
π§ Creating and Deleting Instances
In Uniface 10.4, you control component instances with two main commands:
- newinstance - Creates a new instance
- deleteinstance - Removes an instance
π Simple Example
; Create a new instance
newinstance "MyComponent", MyHandle
; Do something with it
activate MyHandle, "DoSomething"
; Clean up when done
deleteinstance MyHandle
π What are Attached Instances?
An attached instance is a special type of component instance that stays connected to the component that created it. It's like a child holding their parent's hand - when the parent leaves, the child follows! π¨βπ§
You create attached instances in two ways:
- Using the
/attached
switch with the newinstance command - Setting the Modality & Attachment widget property to "Non-Modal, Attached"
π― Why Use Attached Instances?
Attached instances are great for automatic cleanup! When the parent component exits, all attached instances are automatically deleted. This means you don't have to remember to manually delete them - Uniface does the housekeeping for you! π§Ή
π Attached Instance Example
; Create an attached instance
newinstance /attached "DialogComponent", MyDialog
; The dialog will automatically close when
; this component exits - no cleanup needed!
π Component Signatures and Interfaces
Every component has a signature - think of it as a contract that defines what operations you can call. You can invoke these operations using the activate statement or through handles.
π Activation Example
; Activate an operation on an instance
activate MyHandle, "ProcessData", InputParam, OutputParam
ποΈ Memory Management Tips
Component instances created with handles use reference counting. This is an automatic memory management technique where Uniface keeps track of how many references point to an instance. When the reference count drops to zero, the instance is automatically deleted. Smart! π§
β οΈ Important Reminders
- Always clean up instances you create (unless they're attached)
- Multiple instances of the same component can run simultaneously
- Attached instances automatically delete when parent exits
- Use handles for better memory management
π Conclusion
Component instances in Uniface 10.4 give you powerful control over your application's runtime behavior. Whether you need multiple forms running at once or automatic cleanup with attached instances, understanding these concepts will make your Uniface development much smoother! π
Happy coding! π»β¨
Top comments (0)