



    _______________________________________________________________________
                                      Chapter 5: The Current Object   47
    ________________________________________________________________________


    CHAPTER FIVE: THE CURRENT OBJECT

    This chapter describes HyperPAD's facilities for referencing the current
    object, the object that first received the message, and the object whose
    script is currently executing. Reference each of these directly with the
    object names: currentObject, target, and me.


    THE CURRENT OBJECT

    The current object is either a highlighted button, or a field that is
    highlighted or being edited. The current object will only change when
    the focus changes, either by pressing TAB or clicking on a different
    object.

    You can refer to the current object in a script using the reserved
    object name currentObject, like the following example:

    set the color of the currentObject to red;

    put "hello there" into the currentObject;

    Also, you can determine the full name of the current object using the
    currentObject() function:

    put the currentObject;

    if word 1 of currentObject() is "bkgnd" then
      answer "The current object is on the background";

    This function returns the name of the current object in the form:

    page button id 2

    page field id 5

    bkgnd button id 45

    bkgnd field id 3



    _______________________________________________________________________
                                      Chapter 5: The Current Object   48
    ________________________________________________________________________


    THE TARGET

    The target references the object that initially received the message.
    This is the object at the start of the hierarchy for this message,
    either a button, a field, or a page. Use the target as an object in
    scripts, like in the following examples:

    put "Wowee" into the target;

    if the hilite of the target then
      set the focus to button "Help";

    set the check of the target to false;

    set the color of the target to blue;

    You can also refer to the name of the target using the target()
    function. Examples of returned text are:

    page field id 2

    bkgnd button id 1

    page id 3

    These statements use the target () function:

    put the target into the message box;

    if word 2 of target() is "button" then
      set the check of the target to 31;

    A good example of the use of target is shown with the following two page
    handlers that modify a button's border when the mouse enters the
    button's rectangle.

    handler mouseEnter;
    begin
      if word 2 of target() is "button" then
        set the edgeType of the target to 2;
    end;

    handler mouseLeave;
    begin
      if word 2 of target() is "button" then
        set the edgeType of the target to 1;
    end;



    _______________________________________________________________________
                                      Chapter 5: The Current Object   49
    ________________________________________________________________________


    THE CURRENT EXECUTING OBJECT

    The owner of the currently executing script can be referred to by the
    object named me. For example:

    put the name of me into the message box;

    get the rectangle of me;

    if the loc of me is "10,10" then
      set the loc of me to 20,20;

    The following statements belong in a field's script:

    put "Hello World" into me;

    put page field 2 before me;

    Note: Care must be taken when using me, make sure that the use of me is
    consistent with the type of object that owns the script. For example,
    you would not want to put the following statement into a button's
    script:

    put "hello world" into me;

    This statement will only work within a field's script.


    REFERENCING CURRENT OBJECTS WITH "THIS"

    You can reference the current page, background, or pad with the word
    this. For example, all of the following refer to current objects in the
    hierarchy.

    this page

    this background

    this pad

    You can use these object names in your PADtalk statements:

    go to this page;

    put the name of this background into msg;

    if the name of this pad is "home" then quit;

    set the cantDelete of this page to true;

    You cannot use the word this to refer to buttons or fields.