macros userform

Upload: ricktdelagezs

Post on 20-Feb-2018

243 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/23/2019 Macros UserForm

    1/12

    Copyright: 2009 Quest Software, Inc. 1/12All rights reserved 12/8/2009

    Macros and User Forms

    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 Macrositem. Two user macros are available there:

  • 7/23/2019 Macros UserForm

    2/12

    Copyright: 2009 Quest Software, Inc. 2/12All rights reserved 12/8/2009

    Mark Procedures as Generate macro opens the following user form:

    Select the procedures for which you want to clear the Generatebox. Click Closeto execute the

    macro.

    Add Prefixmacro opens the following user form:

    Define a prefix for attributes. Click Executeto execute the macro.

    These have just been examples of user forms that you can create on your own.

    User Forms - Brief Information:

    You can create and use user forms to interact with Toad Data Modeler during script and

    macro execution. You can enter input parameters or see some output information.

    Function Mainonly creates and displays the user form. Other functionalities must be

    implemented/added via form events or its controls. So, a form is not a dialog.

  • 7/23/2019 Macros UserForm

    3/12

    Copyright: 2009 Quest Software, Inc. 3/12All rights reserved 12/8/2009

    MACRO

    Create Macro

    1. Open Script Explorer.

    2. Right-click the Macrositem and select Add New Macro.

    3. Right-click the new item and select Properties.

    4. On tab General, define properties of the 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 macroAdd 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.

  • 7/23/2019 Macros UserForm

    4/12

    Copyright: 2009 Quest Software, Inc. 4/12All rights reserved 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 macroPhysical Model.

    6. On tab Menu, define whether you want to display the macro in:

    - Macro menu,

    - pop-up menu,

    - both places.

    Parameter Pathspecifies 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.

  • 7/23/2019 Macros UserForm

    5/12

    Copyright: 2009 Quest Software, Inc. 5/12All rights reserved 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.

  • 7/23/2019 Macros UserForm

    6/12

    Copyright: 2009 Quest Software, Inc. 6/12All rights reserved 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");

    var form, lb, ed, chb;

    //Create formform = System.CreateForm('Form','Add Prefix to Attributes',200, 170);

    //Add script that should be executed after you click the Execute button

    form.ExecuteScriptName = 'AddPrefix';

    form.ExecuteMethodName = 'Execute';

    form.CloseAfterExecute = true;

    //Add component Label on the form

    lb = form.AddControl('Label', 5);

    lb.Caption = 'Prefix:';

    //Add component Edit on the form

    ed = form.AddControl('EdPrefix', 1);

    ed.Width = 160;

    //Add component Checkbox on the form

    chb = form.AddControl('ChbOnlyName', 2);

    chb.Caption = 'Modify Caption';

    chb.Checked = true;

  • 7/23/2019 Macros UserForm

    7/12

    Copyright: 2009 Quest Software, Inc. 7/12All rights reserved 12/8/2009

    //Macro can be executed for Attributes, Model or Workspace

    //If macro is executed only for attributes, it relates only to selected attributes.

    var OnlyAttributes = true;

    var i, SelectObject;

    for(i=0; i

  • 7/23/2019 Macros UserForm

    8/12

    Copyright: 2009 Quest Software, Inc. 8/12All rights reserved 12/8/2009

    }

    }

    else

    {

    for(i=0; i

  • 7/23/2019 Macros UserForm

    9/12

    Copyright: 2009 Quest Software, Inc. 9/12All rights reserved 12/8/2009

    FORM

    Create a Form

    To create a form, use the object Systemthat is registered in every script.

    The method you need is called CreateFormand has four optional parameters:

    Example:

    var form = System.CreateForm(FormName, Form Caption, 200, 150);

    1. First ParameterName of form (it mustnt contain spaces and other invalid/not

    permitted characters).

    2. Second ParameterCaption that will be displayed in the heading of the form.

    3. Third ParameterWidth of the form.

    4. Fourth ParameterHeight of the form.

    Functions of Form

    AddControl(ControlName: widestring, ControlType: Integer): IDispatch;

    - ControlNameName under which the control is accessible.

    - ControlTypeNumber of control type that should be created.

    See the following table:

    - 1 - Edit Box

    - 2 - Check Box

    - 3 - Memo

    - 4 - Panel- 5 - Label

    - 6 - Group Box

    - 7 - Radio Button

    - 8 - Combo Box

    - 9 - List Box

    - 10 - Button

    This function adds control on the form.

    ShowModal()

    This function displays the form.

  • 7/23/2019 Macros UserForm

    10/12

    Copyright: 2009 Quest Software, Inc. 10/12All rights reserved 12/8/2009

    Procedures of Form

    AddUserVariable(AName: widestring, DefaultValue)

    - ANameName under which a variable is accessible in events of forms.

    - DefaultValueDefault value. It can be of types integer, widestring or boolean.

    This procedure adds a variable on the form. The variable is then accessible in events via callingthe 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.

    RegisterObject(AName: widestring, AObject: IDispatch)

    - ANameName of object via which it will be accessible in events.

    - AobjectObject that is registered.

    Use this procedure to register objects in events.

    Properties of FormCaptionHeading of the form.

    CloseAfterExecuteTrueWhen you click Execute, the code will be executed and the form

    closed. FalseThe form will not close after execution. False is set up by default.

    ExecuteMethodNameName of method that should be executed when you press the

    Execute button.

    ExecuteScriptNameName 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

    ExecuteMethodNameand ExecuteScriptName. The button will not be visible on the form then.

  • 7/23/2019 Macros UserForm

    11/12

    Copyright: 2009 Quest Software, Inc. 11/12All rights reserved 12/8/2009

    EVENTSTo 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

    AlignAlignment of control. Possible values to use:

    0 No alignment

    1 Alignment - Top

    2 Alignment - Bottom

    3 Alignment - Left

    4 Alignment - Right

    5 AlignmentJustify

    AnchorTop, AnchorBottom, AnchorLeft, AnchorRightDetermines the position of control.

    Default placetop left-hand corner.

    ParentControl on which a control is placed. Default position of all controls is on the form and

    this property is not set up.

    Note: Description of value Align 0..5:

    alNone - The control remains where it was placed. This is the default value.

    alTop- The control moves to the top of its parent and resizes to fill the width of its parent. The

    height of the control is not affected.

    alBottom- The control moves to the bottom of its parent and resizes to fill the width of its

    parent. The height of the control is not affected.

    alLeft- The control moves to the left side of its parent and resizes to fill the height of its parent.

    The width of the control is not affected.

    alRight- The control moves to the right side of its parent and resizes to fill the height of its

    parent. The width of the control is not affected.

    alClient- The control resizes to fill the client area of its parent. If another control already

    occupies part of the client area, the control resizes to fit within the remaining client area.

  • 7/23/2019 Macros UserForm

    12/12

    Copyright: 2009 Quest Software, Inc. 12/12All rights reserved 12/8/2009

    BUTTON

    Event

    OnClickOccurs when you click the button.

    CHECKBOX

    Event

    OnClickOccurs when the check in checkbox is changed.

    COMBO-BOX

    Event

    OnSelect - Occurs when combo box is selected.

    EDIT

    Event

    OnChangeTextOccurs when text in edit box is changed.

    MEMO

    Event

    OnChangeTextOccurs when text in memo is changed.

    RADIO BUTTON

    Event

    OnClickOccurs when the button is selected.

    For more properties, please read the Reference Guide (Help menu | Reference, Expert modemust 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.