Ole4D Scripting, How To

Advices

Resizing and alignment

You have to enable the On Resize event on the 4D form which contains the plug-in and execute the Redraw Window command each time the form is resized.
Example:
  If (Form event=On Resize )
    REDRAW WINDOW
  End if

Toolbars

In order to avoid the toolbar to "freeze" for Ole documents (like MS Word or Excel for example), you have to call the OCDocWindowActivated command when the form is activated:
  If (Form event=On Activate )
    $i:=OCDocWindowActivated (Area1;1)
  End if

Memory

If you notice problems in the way that the OLE or ActiveX controls are created, first you have to increase the amount of memory allocated to the 4D process in which you use the plug-in.
For example in our database, we use 1-5 MB for a process, because the ActiveX controls from our demo are very complex and require a big amount of memory in order to run properly.
In case you still notice problems you can increase also the amount of stack allocated to the Custom Menus process using the 4D Customizer.

VBS scripting

- in a time consuming VBScript looping structure you should call the Yield method of the SHost object.
- you can create a script host and run several OCRunScript commands on it.
This way you can use procedures and create objects which will remain available on the next call of OCRunScript.
- it is recommended to create a single script host in a process.
And, more important, to use the same script host in events. Especially in events, creating more script hosts, as well as creating and destroying a script host on every event call, leads to increased memory usage and slower execution.
- script hosts are "global" for the 4D application. That is, you can access a script host from all processes - by using its name. This way you can use the Ole/ActiveX/COM objects created within the script host from all processes.
- the VBScript code block executed in a script host can be debugged with a script debugger, as it would be done if the VBS code would be executed in a web page.