Change The RGB Color of an Object in Code using $rgb()

Conditional Color Assignment Using $rgb()

Purpose

In Zim, you can use conditional logic to dynamically change the color of form objects based on runtime conditions such as user input, system status, or validation results. This is achieved using the if, elseif, else, and endif control structures in combination with the $rgb function.


Syntax

 

if condition
    action
elseif condition
    action
else
    action
endif

 


Example: Status-Based Field Coloring

 

if $status = "error"
    form set (fillcolor rgb $rgb(255, 0, 0)) MyForm.MyFormField
elseif $status = "warning"
    form set (fillcolor rgb $rgb(255, 165, 0)) MyForm.MyFormField
else
    form set (fillcolor rgb $rgb(0, 255, 0)) MyForm.MyFormField
endif

 

Explanation

  • If the status is "error", the field is colored red.
  • If the status is "warning", the field is colored orange.
  • For all other statuses, the field is colored green.

Use Cases

  • Form validation feedback (e.g., highlight invalid fields).
  • User role–based UI customization (e.g., different colors for admin vs. guest).
  • System alerts and notifications (e.g., color-coded warnings).
  • Real-time sensor feedback (e.g., temperature thresholds triggering color changes).

Best Practices

  • Keep RGB values consistent with your UI design system.
  • Use descriptive variable names for conditions.
  • Avoid deeply nested conditionals—break logic into reusable procedures if needed.

Python API to Talk to a Zim Database

🔌 ZimAPI Developer Guide (Python Edition)

🚀 What Is ZimAPI?

ZimAPI is a Python interface that connects directly to the ZIM database engine. It allows developers to execute ZIM and SQL commands, manage transactions, transfer files, and interact with persistent data sets—all from Python.

But ZimAPI is more than just a connector. It’s a gateway to ZIM’s integrated database, which offers a unique and developer-friendly feature: automatic data set creation and session-based persistence.


🧠 Why ZIM Is Different

Unlike traditional SQL databases like MySQL or PostgreSQL, ZIM automatically creates a data set every time a query is executed. These data sets behave like dynamic views and remain available for the entire session—no need to define or manage them manually.

In other systems, a Python developer must explicitly request a view or cache query results. In ZIM, this happens automatically:

 

FIND 5 Customers -> sCustomers

 

This creates a set named sCustomers containing up to 5 customer records. You can interact with this set throughout the session:

 

DELETE 1 FROM sCustomers

 

Once the API session ends, ZIM automatically drops the data set. When a new session begins, a fresh set is created based on the new query context.


🛠️ Installation

After completing the full ZIM installation:

  1. Locate zimapi.py in your ZIM installation directory.
  2. Copy it to the directory where your Python scripts will run.

Tip: Keep zimapi.py in a shared utilities folder if you’re working across multiple projects.


🔗 Connecting to ZIM

Basic Setup

 

import zimapi
import os

zim = zimapi.Zimapi()
zim = zim.connect(
    dbname="your_database_name",
    host="localhost",       # Optional
    port=6002,              # Optional
    user="ZIM",             # Optional
    password=""             # Optional
)

print(zim.state)
zim.close()

 

Inline Connection

 

zim = zimapi.Zimapi(
    dbname="your_database_name",
    host="localhost",
    port=6002,
    user="ZIM",
    password=""
)
print(zim.state)
zim.close()

 

Note:

  • dbname is required.
  • host defaults to "localhost"
  • port defaults to 6002 (must match zimconfig.srv if changed)

🧩 Core Methods

zim.execute(command)

Executes a ZIM or SQL command.

 

if zim.execute("DELETE 1 Customers WHERE CustCode = 1") == 0:
    print("Executed successfully.")
elseif zim.state == 1001:
    print("Record not found.")
else:
    print("Error executing statement. Error Code =", zim.state)
endif

 


zim.transaction(), zim.commit(), zim.rollback()

Control explicit transactions for atomic operations.

 

zim.transaction()
zim.execute("UPDATE Customers SET Status = 'Active' WHERE CustCode = 1")
zim.commit()

 

Or roll back if needed:

 

zim.rollback()

 


zim.callproc(procedure_name, arguments)

Call a ZIM procedure with input/output parameters.

 

args = ("12", 7, "?", "?")
res = zim.callproc("MyProc", args)

if res[1] and res[2]:
    print("Result:", res[1], res[2])
else:
    print("Procedure returned no output.")
endif

 


zim.putfile(source, destination, format)

Upload a file from your local machine to the server.

 

zim.putfile("local.txt", "/server/data.txt", "/A")  # Text file

 


zim.getfile(source, destination, format)

Download a file from the server to your local machine.

 

zim.getfile("/server/data.txt", "local_copy.txt", "/A")  # Text file

 


🧵 Cursors & Sets: ZIM’s Secret Weapon

ZIM’s automatic data sets are one of its most powerful features. These sets persist for the duration of the session and behave like dynamic views.

Create and Use a Cursor

 

cur = zim.cursor("FIND 5 Customers")

while cur.rowcount() > 0:
    row = cur.fetchone()
    print(row)
endwhile

 

Or:

 

cur = zim.cursor()
cur.execute("FIND 5 Customers")

 


Cursor Utilities

MethodDescription
cur.close()Closes the cursor.
cur.rowcount()Number of rows available.
cur.fetchone()Fetches the next row.
cur.rownumber()Current row number.
cur.getname(index)Field name by index.
cur.describe(name)Field metadata.
cur.scroll(amount)Scrolls cursor by rows or to "TOP" / "BOTTOM"

📦 Sets: Persistent Views of Data

Sets are logical collections of rows that persist across the session. They behave like views and can be reused across multiple operations.

Create a Set

 

cur = zim.cursor("FIND 5 Customers -> sCustomers")

 

Manipulate the Set

 

zim.execute("DELETE 1 FROM sCustomers")

 

Use sets to:

  • Cache filtered data
  • Perform batch operations
  • Share views across procedures

🧪 Real-World Use Cases

🔄 1. Transactional Integrity

Wrap multiple operations in a transaction to ensure atomicity.

📞 2. Business Logic via Procedures

Trigger backend logic stored in ZIM procedures—like calculating discounts or validating credentials.

📁 3. Secure File Sync

Automate secure file transfers between client and server for compliance logs or audit trails.

📊 4. Dashboard Integration

Pull live data from ZIM into a Python-based dashboard using cursors and sets.


🧭 Summary

ZimAPI for Python is a powerful and developer-friendly interface that brings ZIM’s integrated database and automatic data set creation into your Python applications. It simplifies data access, enhances performance, and reduces boilerplate code—making it ideal for enterprise automation, smart dashboards, and intelligent safety systems.

Whether you’re modernizing legacy infrastructure or building new solutions, ZimAPI gives you the tools to do it efficiently and elegantly.

C-Sharp API to talk to a Zim Database

🔌 ZimAPI Developer Guide (C# Edition)

🚀 What Is ZimAPI?

ZimAPI for C# is a powerful interface that connects your .NET applications directly to the ZIM database engine. It enables developers to execute ZIM and SQL commands, manage transactions, transfer files, and interact with persistent data sets—all within a C# environment.

But ZimAPI is more than just a connector. It’s a gateway to ZIM’s integrated database, which offers a unique and developer-friendly feature: automatic data set creation and session-based persistence.


🧠 Why ZIM Is Different

Unlike traditional SQL databases like MySQL or PostgreSQL, ZIM automatically creates a data set every time a query is executed. These data sets behave like dynamic views and remain available for the entire session—no need to define or manage them manually.

In other systems, a developer must explicitly request a view or cache query results. In ZIM, this happens automatically:

 

FIND 5 Customers -> sCustomers

 

This creates a set named sCustomers containing up to 5 customer records. You can interact with this set throughout the session:

 

DELETE 1 FROM sCustomers

 

Once the API session ends, ZIM automatically drops the data set. When a new session begins, a fresh set is created based on the new query context.


🛠️ Installation

After completing the full ZIM installation:

  1. Locate zimapi.cs in your ZIM installation directory.
  2. Copy it to the directory where your C# application will be developed.
  3. Reference the compiled ZimAPI.dll in your project.

🌐 Globals

ZimAPI provides several global constants for convenience:

ConstantDescription
TOPIndicates the first record in a set
BOTTOMIndicates the last record in a set
UTF8Indicates a UTF-8 encoded ZIM database
ANSIIndicates an ANSI encoded ZIM database
NO_ERRORIndicates no error occurred

🔗 Connecting to ZIM

Basic Setup

 

using ZimConnection;

ZimAPI Conn = new ZimAPI();
Conn.Connect("DatabaseName", "localhost", 6002, "ZIM", "");
System.Console.WriteLine(Conn.State);
Conn.Close();

 

Inline Constructor

 

using ZimConnection;

ZimAPI Conn = new ZimAPI("DatabaseName", "localhost", 6002, "ZIM", "");
System.Console.WriteLine(Conn.State);
Conn.Close();

 

Note:

  • DatabaseName is required.
  • HostName defaults to "localhost"
  • PortNumber defaults to 6002 (must match zimconfig.srv if changed)
  • UserName defaults to "ZIM"
  • Password defaults to ""

🧩 Core Methods

Conn.Execute(command)

Executes a ZIM or SQL command.

 

if Conn.Execute("DELETE 1 Customers WHERE CustCode = 1") == 0
    System.Console("Executed successfully.")
elseif Conn.State = 1001
    System.Console("Record not found.")
else
    System.Console("Error executing statement. Error Code is = " + Conn.State + ".")
endif

 

Conn.Transaction(), Conn.Commit(), Conn.Rollback()

Control explicit transactions for atomic operations.

 

Conn.Transaction();
Conn.Execute("UPDATE Customers SET Status = 'Active' WHERE CustCode = 1");
Conn.Commit();

 

Or roll back if needed:

 

Conn.Rollback();

 

Conn.Callproc(procedure)

Call a ZIM procedure with input/output parameters.

 

string[] Result = Conn.Callproc("MyProc(\"12\", 7, \"?\", \"?\")");

if Result[1] != null and Result[2] != null
    System.Console("Result: " + Result[1] + ", " + Result[2])
else
    System.Console("Procedure returned no output.")
endif

 

Conn.Putfile() / Conn.Getfile()

Transfer files between client and server.

 

Conn.Putfile("local.txt", "/server/data.txt", "/A");  // Upload text file
Conn.Getfile("/server/data.txt", "local_copy.txt", "/A");  // Download it back

 

Conn.ErrorMessage() / Conn.ErrorCode()

Retrieve the last error message or code.

 

System.Console("Error: " + Conn.ErrorMessage());
System.Console("Code: " + Conn.ErrorCode());

 


🧵 Cursors & Sets: ZIM’s Secret Weapon

ZIM’s automatic data sets are one of its most powerful features. These sets persist for the duration of the session and behave like dynamic views.

Create and Use a Cursor

 

ZimAPI.ZimCursor MyCursor = Conn.Cursor("FIND 5 Customers");

while MyCursor.RowCount() > 0
    string row = MyCursor.FetchOne();
    System.Console(row);
endwhile

 

Or:

 

ZimAPI.ZimCursor MyCursor = Conn.Cursor();
MyCursor.Execute("FIND 5 Customers");

 

Cursor Utilities

MethodDescription
MyCursor.Close()Closes the cursor.
MyCursor.RowCount()Number of rows available.
MyCursor.FetchOne()Fetches the next row.
MyCursor.RowNumber()Current row number.
MyCursor.ValueOf(name)Gets field value by name.
MyCursor.ValueOf(index)Gets field value by index.
MyCursor.GetName(index)Gets field name by index.
MyCursor.FieldCount()Number of fields in the record.
MyCursor.Scroll(amount)Scrolls cursor by rows or to TOP / BOTTOM.

📦 Sets: Persistent Views of Data

Sets are logical collections of rows that persist across the session. They behave like views and can be reused across multiple operations.

Create a Set

 

ZimAPI.ZimCursor MyCursor = Conn.Cursor("FIND 5 Customers -> sCustomers");

 

Manipulate the Set

 

MyCursor.Execute("DELETE 1 FROM sCustomers");

 

Use sets to:

  • Cache filtered data
  • Perform batch operations
  • Share views across procedures

🧪 Real-World Use Cases

1. Smart Form Logic

Use ZimAPI to dynamically change UI elements based on backend data.

🔄 2. Transactional Integrity

Wrap multiple operations in a transaction to ensure atomicity.

📞 3. Business Logic via Procedures

Trigger backend logic stored in ZIM procedures—like calculating discounts or validating credentials.

📁 4. Secure File Sync

Automate secure file transfers between client and server for compliance logs or audit trails.

📊 5. Dashboard Integration

Pull live data from ZIM into a C#-based dashboard using cursors and sets.


🧭 Summary

ZimAPI for C# is a powerful and developer-friendly interface that brings ZIM’s integrated database and automatic data set creation into your .NET applications. It simplifies data access, enhances performance, and reduces boilerplate code—making it ideal for enterprise automation, smart dashboards, and intelligent safety systems.

Whether you’re modernizing legacy infrastructure or building new solutions, ZimAPI gives you the tools to do it efficiently and elegantly.

ZIM Auxiliary Relationships

ZIM’s Auxiliary Relationships are predefined relationships to associate Data Dictionary objects thus speeding Zim applications development.

The Predefined Relationships

NAMEMEANING
EntFieldsIt’s a relationship between EntitySets and their associated Fields.
RelFieldsIt’s a relationship between Relationships with fields and their associated Fields.
DocFieldsIt’s a relationship between Documents with fields and their associated Fields.
EntRolesIt’s a relationship between EntitySets and their associated Roles.
RelRolesIt’s a relationship between Relationships and their associated Roles.
FormFormFieldsIt’s a relationship between Forms and their associated FormFields.
DispDispFormsIt’s a relationship between Displays and the Forms belonging to these Displays.
MenuFormFieldsIt’s a relationship between Menus and their associated FormFields.

Remarks

When a new Zim database is first created, the above auxiliary relationships are also automatically created to be used in Zim development.

Example

To find all fields belonging to the entity sets “Customers” and “Invoices”:

find Ents EntFields Fields where Ents.EntName in ("Customers", "Invoices") -> sMySet

Check whether there are any relationships with fields:

find Rels RelFields Fields
if $SetCount = 0
    out "No Relationships with Fields"
endif

Error Trace

Indicates whether errors raised during a Zim session have to be written to the corresponding error trace file or not.

error trace yes/no

where yes indicates that all errors must be written to the error trace file up to the limit specified by the Maximum Error Trace Size configuration option.

Remarks

Although it may save some disk space, avoiding error printing may lead to undetected error situations. Errors and warnings are raised for a reason and well-behaved Zim applications would seldom raise errors. Therefore, it’s a wise recommendation to leave this option as yes (the default setting) and to check the error files from time to time for existing errors or warnings.

Valid Settings

The default value for all operating environments is yes.

Field WdgType

A numeric code indicating the “class” (field or widget type) of the associated form field.

Valid Values

WdgType = {30 where FT = “0”, 31 where FT = “1”,

A numeric value ranging from 1 to the maximum available widgets according to the table below:

CodeMeaning
1Label
2Entry Field
3ToggleButton
4PushButton
5Menu Item
6Frame
7ListBox
8ComboBox
9OptionBox
10Picture
11Graphic
12Divider
13ScrollBar
14UserMessage
17OLE Object
19TabControl
20TabPage
21GridControl
22Calendar
23Camera
24TreeView
25Signature
26BarCode
27ProgressBar
28TreeView Node
29ListView
30Video
31WebPage

ZIM Software Improvements

Differences from Zim:X distributed by The SmartCone Technologies Inc. and all Zim versions up to Zim 9.00 distributed by Zim Databases Inc.:

Introducing the JSON processing via the functions $GetJSON and $FindJSON.

Zim:X is full threaded 64 bits in all available platforms.

The commands WINDOW OPEN, WINDOW MOVE, WINDOW SIZE now refer the position and size in pixels.

In the entity set Forms:

  • Removed the no longer used TUI attributes Wdth, Hght, HMargin and VMargin;
  • Removed the currently not used attributes (they will be implemented in the future) WdgHMargin and WdgVMargin;
  • Removed invisible indexes NullDirName and NullObjectKey.

In the entity set Displays (Disps):

  • Removed the no longer used TUI attributes Wdth, Hght, HMargin and VMargin;
  • Removed the currently not used attributes (they will be implemented in the future) WdgHMargin and WdgVMargin;
  • Removed invisible indexes NullDirName and NullObjectKey.

In the entity set DisplayForms (DFS):

  • Removed the no longer used TUI attributes Wdth, Hght, HMargin and VMargin;
  • Removed the currently not used attributes (they will be implemented in the future) MenuType, WdgClass, WdgSubClass, WdgStyle, WdgRow, WdgCol, BC, FC, WdgBackground and all 6 references to RGB colors;
  • Removed invisible indexes NullDirName and NullObjectKey;
  • Added the attribute WdgCSS to accept ad hoc information as they become available.

In the entity set Menus:

  • Removed the no longer used TUI attributes Row and Col;
  • Removed the currently not used attributes (they will be implemented in the future) MenuType, WdgClass, WdgSubClass, WdgStyle, WdgRow, WdgCol, BC, FC, WdgBackground and all 6 references to RGB colors;
  • Removed invisible indexes NullDirName and NullObjectKey;
  • Added the attribute WdgCSS to accept ad hoc information as they become available.

In the entity set FormFields (FFS):

  • Removed the no longer used TUI attributes Row, Col, Wdth, Hght, Fill, HMargin and VMargin;
  • Combined the fields FC, BC and all 6 references to RGB colors to two attributes called WdgFCColor and WdgBCColor;
  • Combined the attributes IT, TE, WdgModified, WdgClick, WdgDblClick into an attribute called WdgCallbacks;
  • The attribute FT (FieldType) was converted from a CHAR(1) to INT and renamed to WdgType because FT could no longer hold new widget types;
  • The attributes WdgOnValue, WdgOffValue, WdgNullValue, WdgOnImage, WdgOffImage, WdgNullImage, MinValue, MaxValue, WdgLargeIncrement and WdgSmallIncrement were removed as separate attributes and placed into WdgCSS when they appear in some widget types;
  • Removed the currently not used attributes (they will be implemented in the future) WdgDragMode, WdgDropTarget, WdgPointerStyle, WdgHMargin and WdgVMargin;
  • Removed invisible indexes NullDirName and NullObjectKey;
  • Added the attribute WdgCSS to accept ad hoc information as they become available.

Python Connection

#pip3 -> python 3.9
# - Instalar com pip3
#pip3 install JayDeBeApi --user
#pip3 install JPype1==0.6.3 --user

import jaydebeapi

#variables to connect to zimjdbc8.jar


jclassname='zim.jdbc.ZJ_Driver'
jdbc_driver_loc = r'C:\Users\xxx\Documents\p01\zimjdbc8.jar'
jdbc_driver_name = 'zim.jdbc.ZJ_Driver'
host='localhost:6002'
#url and login variables
url='jdbc:zim://' + host + '/zimdb01'
login="ZIM"
psw=""

#sql to be executed at the Zim's side.
sql = "SELECT codie, name from test"

#connection to the JDBC driver
conn = jaydebeapi.connect(jclassname=jdbc_driver_name,
url=url, 
driver_args=[login, psw],
jars=jdbc_driver_loc)
#open the cursor
cur = conn.cursor()
#execute the SQL statement
cur.execute(sql)
#print the result 
print(cur.fetchall())...

Field WdgCallbacks

The callback events an object can raise.

Valid Values

An integer code combining the following values:

Code

Meaning

0

No callback events are raised.

1

When the object is modified (MODIFIED).

2

When a click is applied to the object (CLICK).

4

When a double-click is applied to the object (DOUBLECLICK).

8

When a right-click is applied to the object (RIGHTCLICK).

16

When an ActiveX object raises a callback event (ACTIVEX).

32

When a click occurs on the header of the object (HEADER).

64

When the object gets the focus (GOTFOCUS).

128

When the object loses focus (LOSTFOCUS).

256

When the object loses focus after being modified (LOSTFOCUSMODIFIED).

Remarks

Only resizable windows can have menus.

Example: If the object has to raise a GotFocus event and a Click event, the WdgCallbacks would contain (2 + 64) = 66.

Field WdgCSS

Provides extra information about the object being used.

Valid Values

A character string, up to 512 characters long either blank or in JSON format.

Remarks

The WdgCSS values for the objects involved present either a blank value or a free-format JSON syntax containing additional information about the object. This extra information may be Data Dictionary fields valid only to the particular object or implemented for future use.

Example

{"icon": "c:/images/zx.ico", "smallincrement":30}

ZIM:X allows JSON data format to be retrieved by the means of the $FindJSON function if the above value would be stored in FFs.WdgCSS:

LIST FFs FORMAT $FindJSON(WdgCSS, "smallincrement")
30

See Also

$FindJSON

en_CAEnglish