NewCom / CreateObject

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > Data types and variables > iDispatch variables >

NewCom / CreateObject

 

Description

 

Obtain an object reference using COM facilities of Windows.

 

Syntax

 

iDispatchVariable = NewCom(sProgID)

 

Alternate Syntax for compatibility with other programming languages

 

iDispatchVariable = CreateObject(sProgID)

 

Returns

 

iDispatch Variable

 

Parameters

 

Name

Type

Optional

Meaning

sProgId

String

No

Name on an external COM server

 

Remarks

 

If the requested object is in a DLL (in-process server), you will always use the NewCom option, as you're asking for a new object. If the request is successful, the object reference is assigned to the iDispatchVariable.

 

If the requested object is in an EXE (out-of-process server), you may use any of the three options: NewCom, GetCom, AnyCom.

with NewCom: a new instance of a COM application is created.
with GetCom: an interface will be opened on an existing, running application, which has been registered as the active automation object for its class.

with AnyCom: first try to use an existing, running application if available, or a new instance if not.

 

Restrictions

 

See also

 

iDispatch, NewCom, GetCom, AnyCom, Nothing, IsComObject, IsComNothing, CreateObject

 

Examples

 
DIM Xls   AS iDispatch
 
'---The following sentences produces the same result

'---Use one or the other.
Xls = CreateObject("Excel.Application")
Xls = NewCom("Excel.Application")
 
...
Xls = NOTHING