Product and documentation by Aparajita Fishman
All trade names referenced in this document are the trademark or registered trademark of their respective holder.
Active4D is copyright Aparajita Fishman and Victory-Heart Productions.
4th DIMENSION, ACI, ACI US, and 4D Compiler are registered trademarks and 4D, 4D Server, 4D Client, and 4D Insider are trademarks of ACI/ACI US, Inc. or 4D, Inc.
Windows is a trademark of Microsoft Corporation.
Macintosh and Mac OS are trademarks of Apple Computer, Inc.
JavaScript and Java are trademarks of Sun Microsystems, Inc.
First of all, thanks to the makers of PHP for giving me the vision of a better way.
Thanks to the client who asked me to generate every single character of HTML in 4D code, which inspired me to come up with a better way.
Thanks to Mike Erickson for his ongoing inspiration and support and for convincing me that Active4D was worth doing. I hope he is right.
Thanks to Steve Willis and Jim Crate of Deep Sky Technologies for their invaluable assistance with the web server.
Thanks to all of the users for their feedback and encouragement.
And thank you to David Adams for so kindly including a chapter about Active4D in "The 4D Web Companion" and for allowing me to include his HTTP chapter with these docs.
Database and Protocol Support 5
Documentation Archive Contents 9
Key Files 10
Timeouts 11
OEM License 12
Starting a Database from Scratch 12
Installing into a Non-Active4D Database 13
Updating an Existing Active4D 2.0 Database 14
Moving an Active4D Database from 4D 6.5 to 4D 6.7+ 14
Post-Installation Configuration 15
Configuring 4D Client as a Web Server 16
Using the Pre- and Post-Execute Hooks 17
Libraries and the Active4D Directory 19
Path Format 20
The Standard Search Path and Path Lists 22
Active4D.ini 22
Realms.ini 24
Deprecated Plugin Configuration Commands 24
Security 27
Web Server Security = Source Code Security 27
The Whole Fortune 500 Can't Be Wrong 28
Executing/Accessing Non-Web Files 29
The "safe script dirs" Config Option 29
The "safe doc dirs" Config Option 30
The "auto create vars" Config Option 31
HTTP Server 33
Active4D + TCP Layer = Web Server 34
Active4D HTTP Request Handling 35
Executable vs. Non-executable Files 35
POST Handling with the 4D 6.5 Web Server 37
POST Handling With the 4D 6.7+ Web Server 37
POST Handling With Stream-based TCP Layers 37
File Upload Handling With 4D's Web Server 38
Executable Request Handling 38
Non-Executable Request Handling 40
Active4D.ini 41
Realms.ini 45
A4D Execute <type> request Parameters 51
Interpreter 61
Comments 65
Identifiers 66
Data Types 66
Literals 68
Operators 69
break 71
return 71
continue 71
exit 72
Examples 72
Absolute vs. Relative Paths 73
Path Limits 74
Indirect Method Calls (aka Poor Man's method pointers) 76
Collections 77
Local vs. Global Collections 77
Referencing Collection Values 78
Iterating Over a Collection 79
Request Data 80
Working with Character Sets 83
Methods 87
Method Name 87
Method Parameter Declaration 88
Scope 89
Referencing "Global" Local Variables 90
Libraries 95
Load Errors 97
The "lib dirs" Config Option 97
The "lib extension" Config Option 97
The "auto refresh libs" Config Option 99
The "refresh interval" Config Option 100
Differences from Active4D 1.0 100
Event Handlers 103
Modifying the Active4D Library 103
On Request 104
On Authenticate 105
On Session Start 106
On Session End 106
On Execute Start 107
On Execute End 107
4D Commands 109
4D 6.5 Commands 109
4D Command List 110
Command Syntax 115
add element 117
append to array 117
clear array 118
is array 118
join array 119
multisort arrays 120
resize array 121
SELECTION/SELECTION RANGE TO ARRAY 121
set array 122
collection 125
new collection 125
copy collection 128
clear collection 129
get collection 129
set collection 132
is a collection 134
collection has 134
get error page 148
get log level 148
in error 148
log message 149
set error page 149
set log level 150
The Importance of Filename Extensions 152
Uploads and 4D's Web Server 152
copy upload 153
count uploads 153
get upload remote filename 155
get upload size 155
Locking and Unlocking the Globals 163
globals 165
globals has 165
get global 165
get global array 166
get global item 167
get global keys 168
set global 168
set global array 169
count globals 169
delete global 170
lock globals 170
unlock globals 170
Using for each 171
Using Iterators 171
more items 173
next item 174
get item key 174
get item value 174
get item type 175
get item array 175
is an iterator 175
call 4d method 177
call method 177
choose 178
define 180
EXECUTE 182
global 182
import 183
include 184
include into 184
longint to time 185
redirect 186
require 186
throw 187
time to longint 187
Duplicate Query Parameters 196
query params 197
query params has 197
get query param 197
get query params 199
request cookies 203
buffer size 211
clear buffer 211
save output 212
end save output 213
write 216
write blob 217
writebr 218
writeln 218
writep 219
write raw 219
= 220
Cookie Fields 221
Limitations with the 4D 6.7 Web Server 221
response cookies 222
set response cookie domain 224
get response cookie expires 224
set response cookie domain 224
response headers 229
get expires 232
set expires 233
get expires date 233
set expires date 233
get content type 234
set content type 234
current platform 237
get license info 237
get version 238
parameter mode 239
Configuring Related Record Auto-loading 242
Compatibility with Active4D 2.0.x 243
Examples 243
auto relate 245
FIRST/LAST/NEXT/PREVIOUS RECORD 245
GOTO RECORD 246
The Active4D Session Architecture 247
Session ID 247
Session Events 248
When Active4D Sends Session Cookies 248
Session Lifetime 249
Memory Caching of Sessions 250
Session Timeout and Memory Usage 250
session 253
session to blob 253
blob to session 253
get session 254
get session item 255
get session keys 256
set session 256
session has 257
abandon session 259
session id 259
session local 260
session query 260
String Commands and Multibyte Character Sets 264
capitalize 265
cell 265
compare strings 266
concat 266
enclose 267
first not of 268
first of 268
last not of 269
last of 269
left trim 270
mac to html 270
param text 271
Position 273
right trim 273
split string 274
String 275
trim 275
url decode 276
url decode path 276
url decode query 276
url encode 277
url encode path 277
url encode query 277
Document Paths 278
Document Command Enhancements 278
Append document 280
Create document 280
current file 280
current path 281
DELETE FOLDER 282
directory of 282
extension of 283
filename of 283
get root 283
Open document 284
RECEIVE PACKET 284
requested url 285
SEND PACKET 285
Timestamp Format 287
Timestamp Time 287
Using Timestamps 288
timestamp 290
add to timestamp 291
timestamp string 291
timestamp date 292
timestamp time 292
timestamp year 293
timestamp month 293
timestamp day 294
timestamp hour 294
timestamp minute 295
timestamp second 295
auth password 297
auth type 297
auth user 297
authenticate 298
current realm 298
defined 300
get local 301
local variables 301
set local 301
type descriptor 302
undefined 302
variable name 303
Enter the RowSet 317
Using RowSets 319
Debugging 323
a4d_web 323
dump array 324
dump collection 324
dump session 325
Displaying the Session Monitor 329
The Active4D Debugging Console 332
Using the Debugging Console 332
Filtering Console Messages 333
Error Handling 335
The "set error page" Command 337
Log Levels 338
Named Constants 351
Alphabetical 353
Welcome to Active4D! You have chosen the ultimate environment for building world-class web applications with 4D.
A dynamic web scripting environment has four layers: a TCP communications layer, an HTTP server layer, a scripting layer, and a database layer. The different layers can be pictured like this:
The HTTP server builds on top of the TCP layer, and the scripting layer builds on top of the HTTP server. The database is in a separate, independent layer.
Active4D is both an HTTP web server and a server-side HTML-embedded scripting language and development environment.
That's a mouthful. Let's break down the sentence and look at what it means.
An HTTP (HyperText Transfer Protocol) web server is a piece of software that receives HTTP requests, processes those requests and sends an appropriate response to the origin. In essence, this is what a web server does.
4D's built-in web server handles TCP communications and handles most of the HTTP protocol.
Internet Toolkit , better known as ITK, is just what it says -- not an HTTP server, but a toolkit that allows you to write an HTTP server. ITK comes with samples which implement a web server well for most purposes.
HTTP Server Deux is a 4D component that implements a full-fledged HTTP server on top of 4D Internet Commands or ITK.
Active4D implements a full-fledged HTTP server in a plugin. As an HTTP server, it offers:
Scripting languages like JavaScript and Java download their source code to the client browser and execute it there. Active4D, on the other hand, is executed on the server and the source code is removed before the page is sent to the client.
Before the advent of Active4D, to create a dynamic web site using 4D you had to generate all or part of the HTML within 4D methods.
Active4D turns that model inside out -- dynamic HTML generation is directly embedded inside the HTML page.
4D's semi-dynamic tag system, while providing some of the benefits of embedded scripting, still requires you to write many, many 4D methods to handle simple tasks like queries and ordering. In Active4D this is handled directly within the web page. In fact, with Active4D all of your application code can (and in most cases should) exist entirely outside of 4D itself.
To generate dynamic HTML you must have a programming language. Active4D is a full 4D interpreter in a plugin. To program in Active4D you don't need to learn a new syntax or specialized tag language. In many cases you can literally copy 4D code from a method and paste it into a web page to be executed by Active4D.
Active4D supports all 4D data types except for 2D arrays. It implements over 150 of the most important 4D commands, as well as over 200 new commands which add unmatched power to your web application.
Active4D also adds several often-requested extensions to the language, such as the break and return keywords, as well as pass-by-reference.
Active4D comes with a plethora of built-in debugging tools, both on the client side and on the 4D side. In conjunction with all of the other features Active4D provides, there simply is no more powerful or more productive web development environment for 4D, period. Nothing else comes close.
The fully dynamic, embedded scripting implementation in Active4D is the cutting edge of dynamic web technology. And by using this approach you are in good company. Here are just a few little web sites that use fully dynamic embedded scripting:
barnesandnoble.com
capitalone.com (Visa)
compaq.com
dell.com
deltaairlines.com
firstusa.com (Visa)
gateway.com
geico.com (insurance)
homedepot.com
macconnection.com / pcconnection.com
macmall.com
macwarehouse.com
microsoft.com
sears.com
staples.com
walmart.com
My research shows that over 75% of the Fortune 500 uses dynamic embedded scripting languages in their corporate, client and e-commerce web sites. And the numbers are growing.
Here's a simple example of what an Active4D page looks like:
Note that the code is fully embedded in the page, and that except for the writebr command, which writes an expression to the HTML page, the embedded code is 4D code.
During execution, Active4D passes straight HTML through, executes everything inside the <% %> tags, and spits out the following:
The source code has been replaced with the output of the Active4D code. You can find out more about programming with Active4D in See Interpreter
Active4D can do anything that 4D can do in the context of a web page, plus quite a few tricks that would be time-consuming if not impossible to implement in 4D.
If Active4D's commands don't fit the bill, you can write methods and libraries of methods completely within Active4D, using plain text files. And if you need to use a command or plugin that is not in Active4D's language, you can call any 4D method, passing parameters of any type and receiving a result of any type.
Primarily, however, Active4D is designed to act as a conduit between the database and the web page. As such, it excels at the following essential tasks:
Active4D comes with built-in support for 4D's built-in database engine. You could, without much work, write wrapper methods for the various connectivity plugins that would allow you to work with other databases such as Sybase and Oracle.
In addition, you could also easily write method wrappers around the 4D Internet Commands to allow you to access other internet protocols like SMTP.
Several years ago I had the occasion to use another dynamic embedded scripting language called PHP. I was amazed at the power it provided, and more importantly I realized the advantages of the embedded scripting model.
A little later I was hired to work on a vertical market, web-based application that used 4D. I was asked to add a new module to the existing application. To my amazement, this application (which used NetLink) generated every single character of HTML programmatically in a 4D method. This was before 4D offered its web tag system.
Having been exposed to embedded scripting, I quickly saw that this was a fundamentally flawed approach, and I said to myself, "There has to be a better way." So I set about creating one.
I never intended to create Active4D -- it just sort of happened. A few months after I began with a simple 4D-based parser that replaced variable and field names, I had a full working 4D interpreter in a plugin.
A few features and a few months later, Active4D 1.0 was released. That was November of 2000. Since then I had a chance to use Active4D heavily in web projects, and decided it was time to fill in all of the holes in its feature set.
I systematically went down the list of every important feature in the world's leading embedded scripting language, Microsoft's Active Server Pages, also known as ASP (from which Active4D takes its name), and implemented each and every one. And wherever possible I added a few features that ASP doesn't have.
The result is what you see here: Active4D 2.0, the ultimate 4D web environment.
First you must of course download the appropriate files from http://aparajitaworld.com/products/Active4D/downloads.html . Because Active4D supports a number of different platforms and environments, the downloads are organized so that you can easily mix and match just what you need.
There are four elements to Active4D:
Once you have downloaded one of the above archives, you will need to decompress it. Mac archives are in Stuffit 5 format, so you will need Stuffit Expander 5 or better to decompress them. Stuffit Expander is free and readily available from www.aladdinsys.com . Windows archives are in Zip format. There are millions of free Zip expanders available for Windows.
Once you decompress the plugin archive, you will find a single folder.
This folder contains the Active4D plugin itself, which must be placed either in a local or shared MAC4DX folder (on Macintosh) or WIN4DX folder (on Windows).
When you download the ITK or TCP Server Deux shells, there will be other files and plugins which support those shells. They should be placed together with Active4D in a 4DX folder.
Once you decompress the shell archive, you will find a number of files and folders.
The main folder contains a complete working shell which illustrates how to integrate Active4D with either 4D's web server, ITK, or TCP Server Deux. In addition, the shell contains the forms and methods which implement the server-side debugging features of Active4D.
This folder contains libraries and config files which are used by Active4D.
For more information on libraries, see See Libraries For more information on config files, see See Configuration
This folder contains plugins which are necessary to use Active4D (in addition to the Active4D plugin).
This purposely empty folder is a critical security device which is explained in See Circumventing Active4D.