DEV Community

Peter + AI
Peter + AI

Posted on

Unlocking Uniface 10.4: A Practical Guide to the $ude("archive") Function ๐Ÿš€

Hey developers! ๐Ÿ‘‹ If you're working with Uniface, you know that managing and deploying your compiled application resources can sometimes be a challenge. Today, we're diving deep into a powerful ProcScript function that simplifies this process: $ude("archive").

Quick note: This post was crafted with the assistance of an AI to break down the official Uniface 10.4 documentation into a more digestible and practical guide.

What is $ude("archive")? ๐Ÿค”

In simple terms, $ude("archive") is your go-to tool for packaging compiled Uniface runtime objectsโ€”like forms, services, and messagesโ€”into a single Uniface Archive (.uar) file. Think of a .uar file as a specialized ZIP archive for your Uniface application components. This makes deployment and distribution much cleaner. โœจ

This function requires a fully configured Repository and is designed to run on a Windows environment with access to ide.uar.

Two Ways to Archive Your Resources โœŒ๏ธ

The documentation shows two primary methods for using this function. Let's break them down.

Method 1: Archiving a List of Resources at Once

This is the most common and efficient way to create a .uar file. You build a list of all the resources you want to include and then call the function once.

Syntax:

vResult = $ude("archive", "list", ListOfResources, ArchiveFile, {OptionList})
Enter fullscreen mode Exit fullscreen mode
  • "list": Tells the function you're providing a list.
  • ListOfResources: A string containing an associative list of all your resources.
  • ArchiveFile: The name of your output file (e.g., "my_app.uar").
  • OptionList: Optional settings, like adding a description or appending to an existing archive.

โš ๏ธ Important: By default, this method will overwrite an existing archive file. If you want to add to it instead, you must use the "append=true" option!

Example:

Let's say you want to find all your compiled forms and services and pack them into one file.

variables
  string vResourceList, vReturn
endvariables

; 1. Find all compiled application shells and archive them
vResourceList = $ude("lookup", "resources_output;application", "*", "", "")
vReturn = $ude("archive", "list", vResourceList, "MyArchive.uar", "description=My Complete Application Archive")

; 2. Find all forms and APPEND them to the same archive
vResourceList = $ude("lookup", "resources_output;form", "*", "", "")
vReturn = $ude("archive", "list", vResourceList, "MyArchive.uar", "append=true") ; <-- Notice "append=true"!

; 3. Find all services and APPEND them as well
vResourceList = $ude("lookup", "resources_output;service", "*", "", "")
vReturn = $ude("archive", "list", vResourceList, "MyArchive.uar", "append=true")

; Now, "MyArchive.uar" contains applications, forms, and services.
Enter fullscreen mode Exit fullscreen mode

Method 2: Archiving Resources One by One

You can also add resources individually. This method is useful if you need more granular control over the process. When using this method, Uniface keeps the archive file open between calls.

Syntax:

vResult = $ude("archive", ResourceType, ResourceName, ArchiveFile, {OptionList})
Enter fullscreen mode Exit fullscreen mode
  • ResourceType: The type of object (e.g., "form", "service", "message").
  • ResourceName: The name of the specific component.
  • ArchiveFile: The name of the output .uar file.
  • OptionList: Required options for specific resource types, like library or language.

๐Ÿšจ Critical Step: Because the file is held open, you must call lflush or flush when you're done to close the file and save all your changes correctly. Forgetting this step will result in an incomplete or corrupt archive!

Example:

Here's how you could add all messages from a specific library to an archive, one by one.

operation addObjectsToUar
variables
  string vResourceList, vArchive, vObject, vType, vName, vOptions, vReturn
endvariables

; Create a list of all 'message' resources from 'my_lib'
vResourceList = $ude("lookup", "resources_output;message", "*", "library=my_lib;language=usa")

vArchive = "my_lib_messages.uar"

; Loop through the list and add each message to the UAR
forlist vObject in vResourceList
  vType = $itempart(vObject, "TYPE") ; Get the resource type
  vName = $itempart(vObject, "NAME") ; Get the resource name

  clear vOptions
  putitem/id vOptions, "LIBRARY", "my_lib"
  putitem/id vOptions, "LANGUAGE", "usa"

  vReturn = $ude("archive", vType, vName, vArchive, vOptions)
endfor

; VERY IMPORTANT: Close the file to complete the transaction!
lflush $concat(vArchive, ":")

; Your "my_lib_messages.uar" is now ready.
end
Enter fullscreen mode Exit fullscreen mode

Summary & Key Takeaways ๐ŸŽฏ

The $ude("archive") function is a powerful asset for automating your Uniface build and deployment pipeline.

  • โžก๏ธ Use the "list" method for simplicity and performance when archiving many objects.
  • โžก๏ธ Use the one-by-one method for more granular control, but don't forget to lflush!
  • โžก๏ธ Always be mindful of the "append=true" option to avoid accidentally overwriting your work.

Happy coding! ๐ŸŽ‰

Top comments (0)