Addressing Types

Description

There are four basic types of addressing available in Alpha Anywhere.

  • Absolute

  • Incomplete

  • Relative

  • Pointer

Absolute Addresses

Absolute addressing requires that you know the complete address of an object. With absolute addressing you can address any object in Alpha Anywhere from any script. Note: The term 'control' and 'object' are sometimes used interchangeably. A control on a form (e.g. a text box, or a label) is an object.

'These commands open two forms and change a field value in each.
:form.view("customer") 'Open the Customer form.
:form.view("sales")
:customer:last_name.value = "Smith"
:sales:city.value = "Boston"
:customer.commit()'save the record
:sales.commit()

Incomplete Addresses and Object Paths

When writing Xbasic code for an event handler (such as a button's OnPush event) absolute addressing syntax is cumbersome, and is actually bad style. Alpha Anywhere supports a simpler addressing scheme called incomplete addressing. When event code is played, Xbasic sets the object path to be the object that is handling the event. For example the default object path for the OnFetch event on form Customer is :Customer. If you specify an object address that does not begin with a colon then Alpha Anywhere will attempt to find the objects by traversing up the object hierarchy starting at the object path. Therefore, in the code for the events in the Customer form, it is legal, and it is good practice, to specify the object addresses of the controls in the Customer form as:

First_Name
Last_Name
Browse1
Browse1:Column1
Browse1:Column2
Browse1:Column3

Notice how these object addresses do not start with a colon. Since the colon is missing Alpha Anywhere will search for these objects starting from the current object path and traversing the object hierarchy tree upwards until it either finds an object with this name or hits the root.

Alpha Anywhere only travels up the object tree. It never descends down another branch.

Searching the Object Tree Example

Assume that there are two forms open: Form1 and Form2. Each form has these objects:

Form1
    F1
    F2
    Browse1
        C1
        C2
        C3
    Browse2
        C1
        C2
Form2
    F1
    F2
    F3

Now, assume that the following code is attached to an event handler on C2 in Browse2 in Form1. The code for this event handler looks like this:

F1.Value = "HELLO"         'Will find :Form1:F1
Browse1:C1.Value = "TEST" 'Will find :Form1:Browse1:C1
C1.Value = "TEST2"         'Will find :Form1:Browse2:C1
Form2:F2.Value = "TEST3"  'Will find :Form2:F2
F3.Value = "HI"            'Error: Will fail
'Search will not
'descend into Form2

The code fails when you specify just F3. To find F3, you would have to address it as Form2:F3, or :Form2:F3. Incomplete addressing is considered good style because it makes the code portable between forms. You could rename Form1, and the Xbasic code would still work because there are no references to the form name in the object addresses.

Pointer Addresses

A pointer is a variable that references an object. A pointer variable has a type of "Pointer". To define a variable that will be an object pointer, you would use the following Xbasic command:

dim variable_name as P

There are two ways to get a pointer to an object. You can use the object's THIS property, or you can use the OBJ() function. For example, assume that you have a form called F1 which has a button called B1. The address of the B1 button is:

:F1:B1

To create a pointer to this object, you could use either of the following commands:

pointer = :F1:B1.this
pointer = obj(":F1:B1")
Do not confuse the "This" property and the "This" alias. For example, the following is legal: p = this.this. If this code were attached to the OnPush event of a button, it would create an object pointer that referenced the button when the button was pushed.

Example

The following function takes a pointer to an object as a parameter. Define a function that sets several properties.

Function SetupObj as C (Object as P)
    object.font.bold = .T.
    object.font.italic = .T.
End function
'Call the function with a bunch of objects
SetupObj(:Customer:First_name.this)
SetupObj(:Customer:Last_name.this)
SetupObj(:Customer:Address.this)