Gopher Automation Server Sample

This example simulates a smart search business object, which locates a customer that might be contained in one of many different databases. What actually happens is that code in the BeforeOpenTables event of the data environment creates an object based on the gopher class and prompts a user for the database to use. Code in the gopher class opens the appropriate database. This strategy makes it possible for you to use Visual FoxPro in a 3-tiered model where user services are not tightly bound to data services as is the case in many of today's client-server environments.

While this example only provides a choice between the Visual FoxPro TESTDATA and Tastrade sample databases, you can use this basic approach to provide a smart search business object, which knows how and where to look across a corporate network for necessary databases.

To open the project for the gopher sample

  • Type the following in the Command window:

    MODIFY PROJECT (HOME(2) + 'servers\gopher\foxsrch')
    

To run the gopher sample

  1. Open the Foxsrch.pjx project in the Visual FoxPro \Samples\Servers\Gopher folder.

  2. Select Srchdata.prg in the Project Manager and choose Modify.

  3. Change the following line so that FOXHOME is defined to reflect your Visual FoxPro samples folder:

    #DEFINE FOXHOME HOME(2)
    
  4. Save and close Srchdata.prg.

  5. In the Project Manager, choose Build.

  6. In the Build Options dialog box, select Build Executable and choose OK to create Foxsearch.exe. The server is registered when you build the executable file.

  7. Run Wing1.scx in the Visual FoxPro \Samples\Servers\Gopher folder.

The following code is included in the BeforeOpenTables event of the Data Environment in Wing1.scx:

LOCAL oGopher,lUseRemote
THIS.AddObject('cursor1','cursor')
THIS.cursor1.Alias = 'employee'
lUseRemote=(MESSAGEBOX('Do you want to use Remote Data?',36) = 6)

oGopher=CreateObject('FoxSearch.Gopher')
oGopher.UpdateDE(THIS,m.lUseRemote)
RELEASE oGopher

The following code defines the Gopher class. The UpdateDE method takes an object reference to a data environment and a logical value as parameters. Based on the value of the logical value, the UpdateDE method sets different CursorSource values for a cursor in the data environment.

#DEFINE FOXHOME   HOME(2)

DEFINE CLASS Gopher AS Custom OLEPUBLIC
oDERef = ''

PROCEDURE UpdateDE
   PARAMETER oNewDE,lRemote
   IF TYPE('oNewDE')#'O' OR ISNULL(m.oNewDE)
      RETURN .F.
   ENDIF
   THIS.oDERef = m.oNewDE

   IF !m.lRemote
   * Use local data
      THIS.oDERef.cursor1.database = FOXHOME + 'DATA\TESTDATA.DBC'
      THIS.oDERef.cursor1.cursorsource = 'Employee'
   ELSE
   * Use remote data (simiulated)
      THIS.oDERef.cursor1.database = FOXHOME + ;      'Tastrade\DATA\Tastrade.DBC'
      THIS.oDERef.cursor1.cursorsource = 'Employee'
   ENDIF
   THIS.oDERef = ''
ENDPROC

ENDDEFINE

See Also

Solutions Samples | Server Samples