Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create ("instantiate") a Connection object.  To instantiate the object, call XOInstance(), passing the connection name.  If successful, the connection "handle", a nonzero number, is returned in hXO.  Calling XOInstance()  is the equivalent, in code, of the NWIND connection object we created in the Client/Server workspace.  The code is as follows:

    Code Block
    hXO = XOInstance('NWIND')
  2. Instantiate a Query object.   After we have a handle to the Connection object, we can use it to create a Query object.  This is done using QryInstance().  If successful, the query handle will be a nonzero number, returned in hQry.  The code is as follows:

    Code Block
    hQry = QryInstance(hXO)
  3. Execute the Query.  The query handle can be used to execute the query.  To execute a "method" (function), use QryMethod().  The QRY_EXECUTE$ code (equated to 4 in XO_Equates) is used to execute the query.  The third parameter is the actual query to execute.  The code is shown below:

    Code Block
    flag = QryMethod(hQry, QRY_EXECUTE$, "select companyname from customers order by companyname")
  4. Process the Results.  After the query has successfully executed,  the rows are available to BASIC+.  The QRY_GETROW$ code (equated to 5 in XO_Equates) retrieves the next row from Access.  QryMethod()  is called with this code, and the results variable is built through a loop.

    Code Block
    row = ""
    results = ""
    loop
      flag = QryMethod(hQry, QRY_GETROW$, row)
      while flag
        results<-1> = row
      repeat
  5. Destroy the Query and Connection Objects, and populate the combo box.   To prevent memory problems, the query and connection objects must be destroyed after use.  The QRY_DESTROY$ code (equated to 1 in XO_Equates) passed to QryMethod() instructs the server to destroy the Query object.  The XO_DESTROY$ code (also equated to 1 in XO_Equates) passed to XOMethod() instructs the server to destroy the Connection object, closing the connection.  The Set_Property() call sets the LIST property of the combo box, populating it with the results of the query.

    Code Block
      QryMethodQryMethod(hQry, QRY_DESTROY$)
    end
      
    rv = Set_Property (@window : '.COMPANIES', 'LIST', results)
    XOMethod(hXO, XO_DESTROY$)
     
    end