Guides/OLE Automation

From J Wiki
Jump to navigation Jump to search

OLE is a Windows technology that allows client programs to call server programs. Any OLE client can call any OLE server.

OLE Automation is an OLE interface that mimics the server's end-user interface. This allows a client to automate what would otherwise be done manually, and gives the client access to the full power of the server.

J Server

J supports OLE Automation with an in-process server, JDLLServer and an local server, JEXEServer. For example, the server has a method Do which executes a J sentence; and a method GetB which retrieves the value of a variable. If a client runs the method Do "x=. 3+5", this causes the sentence to be executed in the server. The client can then call method GetB to retrieve the value of x.

The JEXEServer runs as a separate application from the client. It provides wd as well as the J Engine and can provide full IDE support. As a developer, you have full access to both client and J development and debug environments.

The JDLLServer is part of the client application and uses the same memory space, i.e. it is an in-process server. A client accesses such servers almost as efficiently as its own native functions. JDLLServer is not as convenient as JEXEServer for development purposes, but it is very efficient and is ideal for runtime applications that don't need wd services.

You can develop your application with JEXEServer, and if appropriate run it in production with JDLLServer.

Registration

The server must be registered with your system before it can be used. The Windows AIO installer does this automatically, and it can be done manually by running jreg.cmd in the J directory. You can always run jreg.cmd to register the servers again, for example you will need to do this if you move the J system files to another directory.

Methods

J server methods:

Do   - execute J sentence
ErrorTextB   - get error text
GetB   - get value of a J variable
SetB   - set value of a J variable
Transpose   - return data transposed

GetB and SetB support utf8 unicode.

Loading Profile

No scripts are loaded when the J server starts. In some cases you may want to load the standard J profile, using the Do method to call the following sequence:

JDLLServer

BINPATH_z_=:1!:46''
ARGV_z_=:,<'oleclient'
(3 : '0!:0 y')<BINPATH,'\profile.ijs'

The first sentence sets BINPATH_z_ as the path to the J.DLL file (standard J bin folder), using the foreign 1!:46''.

The second sentence sets ARGV_z_ as the command line parameters used by profile. You can modify this as appropriate but it must be a list of boxed strings.

The third sentence loads profile.ijs in an unnamed verb.

JEXEServer

A bare invisible Qt IDE Term is always created for each JEXEServer instance.

(3 : '0!:0 y')<BINPATH,'\profile.ijs'
initjqt''

The first sentence loads profile.ijs in an unnamed verb which eventually loads the ide/qt addon.

The second sentence re-initializes the bare Qt IDE Term to a regular one.

The Qt IDE is invisible by default. Use the Show method to show or hide it.

Alternatively, it is also possible to load the standard J profile without loading the qt addon.

IFQT_z_=:0
(3 : '0!:0 y')<BINPATH,'\profile.ijs'

Examples

See examples of calling J from Excel here and from C# here.