4D Development Expert (v21)
Skill Version
- 4D Version: v21
- Skill Version: 1.0
- Docs: Full official 4D v21 documentation embedded in
docs/ (3,387 files)
This skill targets 4D v21 specifically. Do not assume features from other versions exist unless verified in the embedded documentation.
How to Use This Skill
CRITICAL: For any 4D task, ALWAYS prefer reading the embedded documentation files (docs/) over relying on training data. The docs/ folder contains the authoritative 4D v21 reference.
Workflow:
- Check this file for critical rules and routing
- Read the relevant
references/ file for curated knowledge and patterns
- If more detail is needed, read the specific
docs/ file pointed to by the reference
- For edge cases, use grep to search across
docs/
- Only fall back to training data if
docs/ doesn't cover the topic
Priority reading: Always check references/manual-insights.md — it contains real-world corrections from code reviews that override documentation.
Local Conventions
Before providing 4D guidance, check if a local/ directory exists in this skill folder with project-specific conventions:
ls local/*.md 2>/dev/null
If files exist, read them first. The local/ directory (gitignored) can contain:
- Company-specific naming conventions and documentation standards
- Project-specific database schemas
- Version overrides (e.g., if project uses 4D v19.2 instead of v21)
Critical Syntax Rules
These are the most common sources of bugs in 4D code. Know them by heart.
1. Assignment vs Comparison
// WRONG: = is comparison, returns True/False
$name = Request("Enter name") // Compares, doesn't assign!
If ($input = Request("Name")) // WRONG: compares, doesn't assign
// CORRECT: := is assignment
$name:=Request("Enter name") // Assigns
$input:=Request("Name")
If ($input # "") // Then compare separately
Rule: := assigns. = compares. Never mix them.
2. Object Properties Are Case-Sensitive
// Variables: case-INSENSITIVE
$MyVar:="test"
$myvar:="changed" // Same variable!
// Object properties: case-SENSITIVE
$obj.Name:="John"
$obj.name:="Jane" // Different properties!
3. Collection vs Array Indexing
// Collections: 0-based
$col:=New collection("A"; "B"; "C")
$first:=$col[0] // "A"
// Arrays: 1-based with special element zero
ARRAY TEXT($arr; 3)
$arr{1}:="A" // First element
$arr{0}:="default" // Special element zero
4. Null Queries Require Literal Syntax
// WRONG: Null as placeholder doesn't work
$result:=ds.Users.query("email = :1"; Null)
// CORRECT: literal null in query string
$result:=ds.Users.query("email = null")
$active:=ds.Users.query("email != null")
5. Linked Collection Queries
// WRONG: conditions can match DIFFERENT collection elements
ds.Users.query("projects[].status = 'active' AND projects[].budget > 1000")
// CORRECT: [a] links conditions to the SAME element
ds.Users.query("projects[a].status = 'active' AND projects[a].budget > 1000")
6. Numeric Object Properties Are Always Real
$obj:=New object("count"; 5)
Value type($obj.count) // Returns Is real, NEVER Is longint
7. Decimal Separator Is Always Period
$price:=19.99 // CORRECT — always period
$price:=19,99 // WRONG — two separate numbers!
8. 4D has a strict left-to-right precedence
if ($length > 1+$i) // Runtime error: $length>1 -> true -> true+$i -> error
if ($length > (1+$i)) // No error
$result:=3+4*5 // 35
$result:=3+(4*5) // 23
Quick Decision Router
By Task
| Task |
Read First |
Then If Needed |
| Syntax errors, operators |
language-syntax.md |
docs/Concepts/operators.md |
| Data types, conversions |
data-types.md |
docs/Concepts/data-types.md |
| ORDA, entity classes |
orda-modern.md |
docs/ORDA/ordaClasses.md |
| Database queries |
query-patterns.md |
docs/API/DataClassClass.md |
| Error handling |
error-handling.md |
docs/Concepts/error-handling.md |
| Legacy/classic code |
classic-patterns.md |
docs/Concepts/arrays.md |
| Forms, events, UI |
forms-and-ui.md |
events-index.md |
| Web server, REST API |
web-and-rest.md |
rest-index.md |
| Specific class API |
api-index.md |
docs/API/{ClassName}Class.md |
| Specific command |
commands-index.md |
docs/commands/{name}.md |
| Legacy command |
legacy-commands-index.md |
docs/commands-legacy/{name}.md |
By Error / Symptom
| Error or Symptom |
Read |
| "Type mismatch" or wrong type |
data-types.md |
| "Cannot use = to assign" / silent assignment bug |
language-syntax.md |
| Query returns wrong results |
query-patterns.md |
| "Null query" not working |
manual-insights.md |
| Entity/EntitySelection methods |
orda-modern.md then api-index.md |
| Form events not firing |
forms-and-ui.md then events-index.md |
| Process variables not working |
classic-patterns.md |
| REST endpoint 404 or auth error |
web-and-rest.md |
| Transaction or save error |
error-handling.md |
local keyword confusion |
manual-insights.md |
| Need to find a specific 4D command |
commands-index.md |
| Need to find a legacy command |
legacy-commands-index.md |
Docs Navigator
The docs/ folder contains the full official 4D v21 documentation (3,387 files, 48MB). Use this section to find the right file.
Category Quick Lookup
| Need |
Directory |
File Pattern |
Example Path |
| Class API reference |
docs/API/ |
{Class}Class.md |
docs/API/CollectionClass.md |
| ORDA concepts |
docs/ORDA/ |
{topic}.md |
docs/ORDA/entities.md |
| Modern commands |
docs/commands/ |
{command-name}.md |
docs/commands/dialog.md |
| Commands by theme |
docs/commands/theme/ |
{Theme}.md |
docs/commands/theme/JSON.md |
| Language concepts |
docs/Concepts/ |
{topic}.md |
docs/Concepts/classes.md |
| REST endpoints |
docs/REST/ |
${endpoint}.md |
docs/REST/$filter.md |
| Form events |
docs/Events/ |
on{Event}.md |
docs/Events/onClicked.md |
| Form objects |
docs/FormObjects/ |
{type}_overview.md |
docs/FormObjects/listbox_overview.md |
| Web server |
docs/WebServer/ |
{topic}.md |
docs/WebServer/sessions.md |
| Legacy commands |
docs/commands-legacy/ |
{command-name}.md |
docs/commands-legacy/alert.md |
| Settings |
docs/settings/ |
{topic}.md |
docs/settings/web.md |
| Project structure |
docs/Project/ |
{topic}.md |
docs/Project/architecture.md |
| AI Kit |
docs/aikit/ |
various |
docs/aikit/ |
| ViewPro |
docs/ViewPro/ |
various |
docs/ViewPro/ |
| WritePro |
docs/WritePro/ |
various |
docs/WritePro/ |
Search Patterns
When you need to find something specific across docs/:
# Find a command by name
grep -rl "title: CommandName" docs/commands/ docs/commands-legacy/
# Find a class method
grep -rl "\.methodName" docs/API/
# Find usage of a specific function
grep -rl "functionName" docs/ --include="*.md"
# Find a form event
ls docs/Events/on*.md
# Find a form object type
ls docs/FormObjects/*_overview.md
# Find a REST endpoint
ls docs/REST/\$*.md
# Find settings for a topic
grep -rl "keyword" docs/settings/
# Find a legacy command by theme
grep -rl "CommandName" docs/commands/theme/
Index Files
For structured navigation of large categories, read these generated indexes:
| Index |
Content |
Files Indexed |
| api-index.md |
All API classes with key methods |
42 |
| commands-index.md |
Modern commands + theme categories |
65 + 76 |
| concepts-index.md |
Language concept files |
29 |
| orda-index.md |
ORDA documentation structure |
10 |
| rest-index.md |
REST API endpoints |
36 |
| events-index.md |
Form and system events |
61 |
| form-objects-index.md |
Form object types |
54 |
| webserver-index.md |
Web server documentation |
14 |
| legacy-commands-index.md |
Legacy commands by theme |
1,211 |
| all-categories-index.md |
Master navigation |
32 categories |
Reference Files Guide
Curated Knowledge (hand-written, with code examples)
| File |
Covers |
Priority |
| language-syntax.md |
Assignment, operators, control flow, methods, classes, strings, formulas |
High — read for any syntax question |
| data-types.md |
All types, conversions, null/undefined, collections, objects, pointers |
High — read for type errors |
| orda-modern.md |
ORDA architecture, entity classes, computed attributes, shared objects, signals |
High — read for new feature development |
| query-patterns.md |
Query syntax, placeholders, null queries, linked collections, formulas, performance |
High — read for any query work |
| error-handling.md |
Try/Catch, ON ERR CALL, transactions, Throw, logging |
Medium — read when handling errors |
| classic-patterns.md |
Arrays, process variables, pointers, sets, migration strategies |
Medium — read for legacy code |
| forms-and-ui.md |
Forms, events, form objects, list boxes, subforms, form classes |
Medium — read for UI work |
| web-and-rest.md |
Web server, REST API, HTTP handlers, sessions, authentication |
Medium — read for web/REST work |
| manual-insights.md |
Real-world corrections from code reviews — overrides other sources |
Always check for edge cases |
Common Workflows
New Feature Development:
- orda-modern.md for architecture patterns
- query-patterns.md for database operations
- error-handling.md for robust error management
- Specific
docs/API/ files for class method details
Legacy Code Maintenance:
- classic-patterns.md for understanding legacy code
- orda-modern.md for modernization options
- language-syntax.md for syntax questions
Debugging:
- Check Critical Syntax Rules above first
- language-syntax.md for syntax errors
- data-types.md for type errors
- query-patterns.md for query issues
- manual-insights.md for known gotchas
Web/REST Development:
- web-and-rest.md for server and REST patterns
- orda-modern.md for exposed functions
- rest-index.md for specific endpoint docs
External Resources
When the embedded docs don't cover your case:
1---2name: 4d-v213description: Comprehensive 4D v21 development expert with embedded official documentation. Covers ORDA patterns, entity classes, data model classes, queries, classic methods, data types, error handling, forms, events, web server, and REST API. Use when working with 4D files (.4dm), 4D language questions, 4D project structure, entity classes, ORDA queries, database operations, form development, web server configuration, REST API usage, or any 4D-specific syntax issue. Includes full official 4D v21 documentation for on-demand retrieval. Triggers on: .4dm files, 4D code, ORDA, entity selection, dataclass, 4D query, 4D form, 4D web server, 4D REST, 4D command, 4D collection, 4D object.4---56# 4D Development Expert (v21)78## Skill Version910- **4D Version**: v2111- **Skill Version**: 1.012- **Docs**: Full official 4D v21 documentation embedded in `docs/` (3,387 files)1314This skill targets **4D v21** specifically. Do not assume features from other versions exist unless verified in the embedded documentation.1516---1718## How to Use This Skill1920**CRITICAL**: For any 4D task, ALWAYS prefer reading the embedded documentation files (`docs/`) over relying on training data. The `docs/` folder contains the authoritative 4D v21 reference.2122**Workflow:**231. Check this file for critical rules and routing242. Read the relevant `references/` file for curated knowledge and patterns253. If more detail is needed, read the specific `docs/` file pointed to by the reference264. For edge cases, use grep to search across `docs/`275. Only fall back to training data if `docs/` doesn't cover the topic2829**Priority reading**: Always check `references/manual-insights.md` — it contains real-world corrections from code reviews that override documentation.3031---3233## Local Conventions3435Before providing 4D guidance, check if a `local/` directory exists in this skill folder with project-specific conventions:3637```bash38ls local/*.md 2>/dev/null39```4041If files exist, read them first. The `local/` directory (gitignored) can contain:42- Company-specific naming conventions and documentation standards43- Project-specific database schemas44- Version overrides (e.g., if project uses 4D v19.2 instead of v21)4546---4748## Critical Syntax Rules4950These are the most common sources of bugs in 4D code. Know them by heart.5152### 1. Assignment vs Comparison5354```4d55// WRONG: = is comparison, returns True/False56$name = Request("Enter name") // Compares, doesn't assign!57If ($input = Request("Name")) // WRONG: compares, doesn't assign5859// CORRECT: := is assignment60$name:=Request("Enter name") // Assigns61$input:=Request("Name")62If ($input # "") // Then compare separately63```6465**Rule**: `:=` assigns. `=` compares. Never mix them.6667### 2. Object Properties Are Case-Sensitive6869```4d70// Variables: case-INSENSITIVE71$MyVar:="test"72$myvar:="changed" // Same variable!7374// Object properties: case-SENSITIVE75$obj.Name:="John"76$obj.name:="Jane" // Different properties!77```7879### 3. Collection vs Array Indexing8081```4d82// Collections: 0-based83$col:=New collection("A"; "B"; "C")84$first:=$col[0] // "A"8586// Arrays: 1-based with special element zero87ARRAY TEXT($arr; 3)88$arr{1}:="A" // First element89$arr{0}:="default" // Special element zero90```9192### 4. Null Queries Require Literal Syntax9394```4d95// WRONG: Null as placeholder doesn't work96$result:=ds.Users.query("email = :1"; Null)9798// CORRECT: literal null in query string99$result:=ds.Users.query("email = null")100$active:=ds.Users.query("email != null")101```102103### 5. Linked Collection Queries104105```4d106// WRONG: conditions can match DIFFERENT collection elements107ds.Users.query("projects[].status = 'active' AND projects[].budget > 1000")108109// CORRECT: [a] links conditions to the SAME element110ds.Users.query("projects[a].status = 'active' AND projects[a].budget > 1000")111```112113### 6. Numeric Object Properties Are Always Real114115```4d116$obj:=New object("count"; 5)117Value type($obj.count) // Returns Is real, NEVER Is longint118```119120### 7. Decimal Separator Is Always Period121122```4d123$price:=19.99 // CORRECT — always period124$price:=19,99 // WRONG — two separate numbers!125```126127### 8. 4D has a strict left-to-right precedence128129```4d130if ($length > 1+$i) // Runtime error: $length>1 -> true -> true+$i -> error131if ($length > (1+$i)) // No error132133$result:=3+4*5 // 35134$result:=3+(4*5) // 23135```136137---138139## Quick Decision Router140141### By Task142143| Task | Read First | Then If Needed |144|------|-----------|----------------|145| Syntax errors, operators | [language-syntax.md](references/language-syntax.md) | `docs/Concepts/operators.md` |146| Data types, conversions | [data-types.md](references/data-types.md) | `docs/Concepts/data-types.md` |147| ORDA, entity classes | [orda-modern.md](references/orda-modern.md) | `docs/ORDA/ordaClasses.md` |148| Database queries | [query-patterns.md](references/query-patterns.md) | `docs/API/DataClassClass.md` |149| Error handling | [error-handling.md](references/error-handling.md) | `docs/Concepts/error-handling.md` |150| Legacy/classic code | [classic-patterns.md](references/classic-patterns.md) | `docs/Concepts/arrays.md` |151| Forms, events, UI | [forms-and-ui.md](references/forms-and-ui.md) | [events-index.md](references/events-index.md) |152| Web server, REST API | [web-and-rest.md](references/web-and-rest.md) | [rest-index.md](references/rest-index.md) |153| Specific class API | [api-index.md](references/api-index.md) | `docs/API/{ClassName}Class.md` |154| Specific command | [commands-index.md](references/commands-index.md) | `docs/commands/{name}.md` |155| Legacy command | [legacy-commands-index.md](references/legacy-commands-index.md) | `docs/commands-legacy/{name}.md` |156157### By Error / Symptom158159| Error or Symptom | Read |160|-----------------|------|161| "Type mismatch" or wrong type | [data-types.md](references/data-types.md) |162| "Cannot use = to assign" / silent assignment bug | [language-syntax.md](references/language-syntax.md) |163| Query returns wrong results | [query-patterns.md](references/query-patterns.md) |164| "Null query" not working | [manual-insights.md](references/manual-insights.md) |165| Entity/EntitySelection methods | [orda-modern.md](references/orda-modern.md) then [api-index.md](references/api-index.md) |166| Form events not firing | [forms-and-ui.md](references/forms-and-ui.md) then [events-index.md](references/events-index.md) |167| Process variables not working | [classic-patterns.md](references/classic-patterns.md) |168| REST endpoint 404 or auth error | [web-and-rest.md](references/web-and-rest.md) |169| Transaction or save error | [error-handling.md](references/error-handling.md) |170| `local` keyword confusion | [manual-insights.md](references/manual-insights.md) |171| Need to find a specific 4D command | [commands-index.md](references/commands-index.md) |172| Need to find a legacy command | [legacy-commands-index.md](references/legacy-commands-index.md) |173174---175176## Docs Navigator177178The `docs/` folder contains the **full official 4D v21 documentation** (3,387 files, 48MB). Use this section to find the right file.179180### Category Quick Lookup181182| Need | Directory | File Pattern | Example Path |183|------|-----------|-------------|--------------|184| Class API reference | `docs/API/` | `{Class}Class.md` | `docs/API/CollectionClass.md` |185| ORDA concepts | `docs/ORDA/` | `{topic}.md` | `docs/ORDA/entities.md` |186| Modern commands | `docs/commands/` | `{command-name}.md` | `docs/commands/dialog.md` |187| Commands by theme | `docs/commands/theme/` | `{Theme}.md` | `docs/commands/theme/JSON.md` |188| Language concepts | `docs/Concepts/` | `{topic}.md` | `docs/Concepts/classes.md` |189| REST endpoints | `docs/REST/` | `${endpoint}.md` | `docs/REST/$filter.md` |190| Form events | `docs/Events/` | `on{Event}.md` | `docs/Events/onClicked.md` |191| Form objects | `docs/FormObjects/` | `{type}_overview.md` | `docs/FormObjects/listbox_overview.md` |192| Web server | `docs/WebServer/` | `{topic}.md` | `docs/WebServer/sessions.md` |193| Legacy commands | `docs/commands-legacy/` | `{command-name}.md` | `docs/commands-legacy/alert.md` |194| Settings | `docs/settings/` | `{topic}.md` | `docs/settings/web.md` |195| Project structure | `docs/Project/` | `{topic}.md` | `docs/Project/architecture.md` |196| AI Kit | `docs/aikit/` | various | `docs/aikit/` |197| ViewPro | `docs/ViewPro/` | various | `docs/ViewPro/` |198| WritePro | `docs/WritePro/` | various | `docs/WritePro/` |199200### Search Patterns201202When you need to find something specific across `docs/`:203204```bash205# Find a command by name206grep -rl "title: CommandName" docs/commands/ docs/commands-legacy/207208# Find a class method209grep -rl "\.methodName" docs/API/210211# Find usage of a specific function212grep -rl "functionName" docs/ --include="*.md"213214# Find a form event215ls docs/Events/on*.md216217# Find a form object type218ls docs/FormObjects/*_overview.md219220# Find a REST endpoint221ls docs/REST/\$*.md222223# Find settings for a topic224grep -rl "keyword" docs/settings/225226# Find a legacy command by theme227grep -rl "CommandName" docs/commands/theme/228```229230### Index Files231232For structured navigation of large categories, read these generated indexes:233234| Index | Content | Files Indexed |235|-------|---------|---------------|236| [api-index.md](references/api-index.md) | All API classes with key methods | 42 |237| [commands-index.md](references/commands-index.md) | Modern commands + theme categories | 65 + 76 |238| [concepts-index.md](references/concepts-index.md) | Language concept files | 29 |239| [orda-index.md](references/orda-index.md) | ORDA documentation structure | 10 |240| [rest-index.md](references/rest-index.md) | REST API endpoints | 36 |241| [events-index.md](references/events-index.md) | Form and system events | 61 |242| [form-objects-index.md](references/form-objects-index.md) | Form object types | 54 |243| [webserver-index.md](references/webserver-index.md) | Web server documentation | 14 |244| [legacy-commands-index.md](references/legacy-commands-index.md) | Legacy commands by theme | 1,211 |245| [all-categories-index.md](references/all-categories-index.md) | Master navigation | 32 categories |246247---248249## Reference Files Guide250251### Curated Knowledge (hand-written, with code examples)252253| File | Covers | Priority |254|------|--------|----------|255| [language-syntax.md](references/language-syntax.md) | Assignment, operators, control flow, methods, classes, strings, formulas | High — read for any syntax question |256| [data-types.md](references/data-types.md) | All types, conversions, null/undefined, collections, objects, pointers | High — read for type errors |257| [orda-modern.md](references/orda-modern.md) | ORDA architecture, entity classes, computed attributes, shared objects, signals | High — read for new feature development |258| [query-patterns.md](references/query-patterns.md) | Query syntax, placeholders, null queries, linked collections, formulas, performance | High — read for any query work |259| [error-handling.md](references/error-handling.md) | Try/Catch, ON ERR CALL, transactions, Throw, logging | Medium — read when handling errors |260| [classic-patterns.md](references/classic-patterns.md) | Arrays, process variables, pointers, sets, migration strategies | Medium — read for legacy code |261| [forms-and-ui.md](references/forms-and-ui.md) | Forms, events, form objects, list boxes, subforms, form classes | Medium — read for UI work |262| [web-and-rest.md](references/web-and-rest.md) | Web server, REST API, HTTP handlers, sessions, authentication | Medium — read for web/REST work |263| [manual-insights.md](references/manual-insights.md) | Real-world corrections from code reviews — overrides other sources | **Always check** for edge cases |264265### Common Workflows266267**New Feature Development:**2681. [orda-modern.md](references/orda-modern.md) for architecture patterns2692. [query-patterns.md](references/query-patterns.md) for database operations2703. [error-handling.md](references/error-handling.md) for robust error management2714. Specific `docs/API/` files for class method details272273**Legacy Code Maintenance:**2741. [classic-patterns.md](references/classic-patterns.md) for understanding legacy code2752. [orda-modern.md](references/orda-modern.md) for modernization options2763. [language-syntax.md](references/language-syntax.md) for syntax questions277278**Debugging:**2791. Check [Critical Syntax Rules](#critical-syntax-rules) above first2802. [language-syntax.md](references/language-syntax.md) for syntax errors2813. [data-types.md](references/data-types.md) for type errors2824. [query-patterns.md](references/query-patterns.md) for query issues2835. [manual-insights.md](references/manual-insights.md) for known gotchas284285**Web/REST Development:**2861. [web-and-rest.md](references/web-and-rest.md) for server and REST patterns2872. [orda-modern.md](references/orda-modern.md) for exposed functions2883. [rest-index.md](references/rest-index.md) for specific endpoint docs289290---291292## External Resources293294When the embedded docs don't cover your case:295296- **Official docs**: https://developer.4d.com/docs/297- **Community forum**: https://discuss.4d.com/298- **Blog** (feature deep-dives): https://blog.4d.com/299- **GitHub depot** (code examples): https://github.com/4d-depot