Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
INTRODUCTION
Toad Data Modeler supports macros. You can create a macro in Package Explorer or Script
Explorer and modify its properties to display the macro either in main menu or pop-up menu (of
particular object or on the Workspace etc.).
Older Toad Data Modeler versions allowed you to define such macros via a script written in
Script Editor. To execute the script directly, you simply selected the macro in the particular
menu.
Current BETA version is bringing some improvements for using macros - visual components for
macros (User Forms). So, now when you select a macro, a user form can display.
Examples of User Forms:
Right-click the Workspace displays the Macros item. Two user macros are available there:
1/12
12/8/2009
Select the procedures for which you want to clear the Generate box. Click Close to execute the
macro.
Add Prefix macro opens the following user form:
2/12
12/8/2009
MACRO
Create Macro
Use Case:
You want to create a macro that will add a particular prefix to all attributes in your model.
Solution: You will create a macro Add Prefix. The macro will be available via right-click
menu on the Workspace. You want to create a user form where you will define the prefix
and decide if you want to apply the change in Caption of attributes too.
1.
2.
3.
4.
3/12
12/8/2009
Important! Name of macro mustnt contain spaces and other forbidden characters.
The name must start with a character (not number). Then you can use characters,
numbers or possibly _.
The rules dont refer to caption. Caption can be any title you want.
5. On tab Visibility, select where you want to apply the macro Physical Model.
6. On tab Menu, define whether you want to display the macro in:
- Macro menu,
- pop-up menu,
- both places.
Parameter Path specifies position in main menu or pop-up menu. Feel free to define e.g.
Test\My Items.
In this example, you decide to display it only in pop-up menu.
Path box is empty as Macros item is set as default.
4/12
12/8/2009
7. On tab Object Types, select in which object pop-up menu you want to display it. Select
Workspace.
8. Confirm OK.
5/12
12/8/2009
9. Double-click the macro to open Script Editor. Modify the default code.
function Main(){
var App = System.GetInterface("Application");
var Model = App.ActiveModel;
var WS = App.ActiveWorkSpace;
var Log = System.CreateObject("Log");
6/12
12/8/2009
function RenameAttribute(Attribute)
{
Log.Information('Attribute has been renamed from "'+Attribute.Name+'" to
"'+EdPrefix.Text+Attribute.Name+'"');
if (ChbOnlyName.Checked)
{
Attribute.Caption = EdPrefix.Text+Attribute.Caption;
}
else
{
Attribute.Name = EdPrefix.Text+Attribute.Name;
}
}
function Execute()
{
var i, j, SelectObject, Ent;
if (Instance.OnlyAttributes)
{
for(i=0; i<SelectedObjects.Count;i++)
{
SelectObject = SelectedObjects.GetObject(i);
RenameAttribute(SelectObject);
Copyright: 2009 Quest Software, Inc.
All rights reserved
7/12
12/8/2009
}
}
else
{
for(i=0; i<Model.Entities.Count; i++)
{
Ent = Model.Entities.GetObject(i);
for(j=0; j<Ent.Attributes.Count; j++)
{
SelectObject = Ent.Attributes.GetObject(j);
RenameAttribute(SelectObject);
}
}
}
Model.RefreshModel();
}
Result: Right-click the Workspace |Macros |Add Prefix to open the user form.
8/12
12/8/2009
FORM
Create a Form
To create a form, use the object System that is registered in every script.
The method you need is called CreateForm and has four optional parameters:
Example:
var form = System.CreateForm(FormName, Form Caption, 200, 150);
1. First Parameter Name of form (it mustnt contain spaces and other invalid/not
permitted characters).
2. Second Parameter Caption that will be displayed in the heading of the form.
3. Third Parameter Width of the form.
4. Fourth Parameter Height of the form.
Functions of Form
AddControl(ControlName: widestring, ControlType: Integer): IDispatch;
-
ShowModal()
This function displays the form.
9/12
12/8/2009
Procedures of Form
AddUserVariable(AName: widestring, DefaultValue)
-
This procedure adds a variable on the form. The variable is then accessible in events via calling
the Instance.VariableName. The variable is accessible across events. If you change a content of
the variable in one event, the changed status will be accessible in another event.
Properties of Form
Caption Heading of the form.
CloseAfterExecute True When you click Execute, the code will be executed and the form
closed. False The form will not close after execution. False is set up by default.
ExecuteMethodName Name of method that should be executed when you press the
Execute button.
ExecuteScriptName Name of script for calling out the method when you click the Execute
button.
Note: If you dont want to use the button Execute, do not set up the properties
ExecuteMethodName and ExecuteScriptName. The button will not be visible on the form then.
10/12
12/8/2009
EVENTS
To assign events, assign the component of particular event to properties of names
NameEventScriptName, NameEventMethodName with reference to particular service method.
Example:
Button.OnClickScriptName = MyScript;
Button.OnClickMethodName = DoOnClick;
CONTROL
Control is an ancestor from which all controls, including the form, inherit.
Properties of Control
Align Alignment of control. Possible values to use:
0
1
2
3
4
5
No alignment
Alignment - Top
Alignment - Bottom
Alignment - Left
Alignment - Right
Alignment Justify
11/12
12/8/2009
BUTTON
Event
OnClick Occurs when you click the button.
CHECKBOX
Event
OnClick Occurs when the check in checkbox is changed.
COMBO-BOX
Event
OnSelect - Occurs when combo box is selected.
EDIT
Event
OnChangeText Occurs when text in edit box is changed.
MEMO
Event
OnChangeText Occurs when text in memo is changed.
RADIO BUTTON
Event
OnClick Occurs when the button is selected.
For more properties, please read the Reference Guide (Help menu | Reference, Expert mode
must be selected). See objects: UserButton, IUserCheckBox, IUserComboBox, UserControl,
UserEdit, UserFormBasic, UserForm, UserGroupBox, IUserLabel, UserListBox, UserMemo,
IUserPanel, UserRadioButton, UserStrings.
Note: Reference Guide is not being updated for Beta versions. The document will be updated for
next commercial release of Toad Data Modeler. Thank you.
12/12
12/8/2009