xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

GetActiveObject()

Retturns an instantiated OLE Automation object.

Syntax

GetActiveObject( <cProgID> ) --> oOleAuto

Arguments

<cProgID>
This is a character string holding the OLE ProgID of the application instance to use for automation. They consist of a program name, usually followed by ".Application". For example:
   cProgID := "Word.Application"              // MS Office Word
   cProgID := "Excel.Application"             // MS Office Excel
   cProgID := "InternetExplorer.Application"  // Internet Explorer

Return

The function returns the TOleAuto object of an existing OLE automation instance. When the the requested OLE automation object is not running, a runtime error is raised.

Description

The function GetActiveObject() is similar to CreateObject(). Hower, it searches a running instance of the desired OLE application, rather than loading a new instance into memory.

Info

See also:CreateObject()
Category: OLE Automation , xHarbour extensions
Source:rtl\win32ole.prg
LIB:xhb.lib, ole.lib
DLL:xhbdll.dll

Example

// The example shows the typyical programming pattern to request a running
// OLE application. GetActiveObject() first requests an instantiated OLE
// object. When this fails, the CreateObject() functions tries to instantiate
// the OLE application. If this fails again, the requested OLE object is not
// (properly) installed on the computer and the xHarbour application quits.

   PROCEDURE Main
      LOCAL oOLE

      TRY
         oOLE := GetActiveObject( "InternetExplorer.Application" )
      CATCH
         TRY
            oOLE := CreateObject( "InternetExplorer.Application" )
         CATCH
            Alert( "ERROR! IE not avialable. [" + Ole2TxtError()+ "]" )
            QUIT
         END
      END

      <... code for OLE automation ...>
      oOle:quit()
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe