WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE COM ADO CDO ADSI LDAP
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

OLE COM Default Member Discussion


Here are some terms you will need to know when referring to objects and their capabilities.

Objects Objects are containers that contain properties, methods, and events. Objects are created from classes; thus an object is said to be an instance of a class. To use an object, you must keep a reference to it in an object variable.

Properties Properties are the data that describe an object.

Methods Methods are things you can tell the object to do.

Events Events are things the object does; you can write code to be executed when events occur.

Class The class defines an object's interfaces, whether the object is public, and under what circumstances it can be created. Descriptions of classes are stored in type libraries, and can be viewed with object browsers.

Interface A set of properties and methods is called an interface.

Using Default Properties

Many objects have default properties.

In VB you can use default properties to simplify your code, because you don't have to refer explicitly to the property when setting its value. For an object where Value is the default property, these two statements are equivalent:

   object = 20
and
   object.Value = 20
IMPORTANT: In WinBatch, you *must* explictly refer to the property when setting its value.
object.Value = 20

Using Default Properties with Object Variables

In Visual Basic when a reference to an object is stored in an object variable, you can still use the default property. The following code fragment demonstrates this.
   Private Sub Command1_Click()
      Dim obj As Object
      ' Place a reference to Text1 in the object variable.
      Set obj = Text1
      ' Set the value of the default property (Text).
      obj = "hello"
   End Sub
In the code above, obj = "hello" is exactly the same as typing obj.Text = "hello".

In WinBatch, you *must* use obj.Text = "hello". Where 'Text' is the default property.

Using Default Properties with Variants

In Visual Basic, accessing default properties is different when an object reference is stored in a variable of type Variant, instead of in an object variable. This is because a Variant can contain data of many different types.

For example, you can read the default property of Text1 using a reference in a Variant, but trying to assign the string "goodbye" to the default property doesn't work. Instead, it replaces the object reference with the string, and changes the Variant type.

   Private Sub Command1_Click()
      Dim vnt As Variant
      ' Set the default property (Text) to "hello".
      Text1 = "hello"
      ' Place a reference to Text1 in the Variant.
      Set vnt = Text1
      ' Display the default property of Text1, and show
      '	that the Variant contains an object reference.
      MsgBox vnt, , "IsObject? " & IsObject(vnt)
      ' Attempt to set the default property of Text1.
      vnt = "goodbye"
      MsgBox vnt, , "IsObject? " & IsObject(vnt)
   End Sub
When you run the application and click the command button, you first get a message box displaying the current value of the default property of Text1, "hello," which you can verify by looking at Text1. The caption of the message box confirms that the Variant contains an object reference that is, a reference to Text1.

When you click the OK button on the message box, "goodbye" is assigned to the Variant, destroying the reference to Text1. Another message box is then displayed, showing the contents of the Variant which as you can see doesn't match the current value of Text1.Text.

The caption of the message box confirms that the Variant no longer contains an object reference it now contains the string "goodbye."

As you can see the VB SET command allows for a object variable to REFERNCE an other object variable. WinBatch doesn't offer a SET command. By Default in WinBatch when you assign an object variable to another object variable a object reference is stored instead of its value. Therefore you can not read the default property of Text1 merely using an object variable. You MUST specify the default member!

      ; Set the default property (Text) to "hello".
      obj.Text = "hello"
      ; Place a reference to Text1 in the Variant.
      vnt = Text1
      ; Show that the Variant contains an object reference.
		ret = VarType(vnt)
		if ret == 1024 then str = "Is an Object"
		else str = "Is not an Object"
      Message(vnt,StrCat("Is Object? ",str))

How to Determine Default Member of an Object

First you will need the OLE/COM Object Viewer. It can be downloaded from Microsoft at http://www.microsoft.com/com/resources/oleview.asp

The OLE/COM Object Viewer requires either Windows® 95 or Windows NT® version 4.0 with Windows NT 4.0 Service Pack 3 or later. You must have also installed Internet Explorer 3.0 or later , DCOM95, or the ActiveX Software Development Kit (SDK).

In order to determine the default member, you will need to locate the member whose dispatch id is zero. Remember: There can be only one default member for an object. Therefore there will only be on member (property or method) with an id of 0.

Open the OLE/COM Object Viewer.
Select 'All Objects'.
Select 'Dictionary Class'.
Double click 'IDispatch'.
Press 'View TypeInfo' button
In the left hand frame of the ITypeInfo Viewer look for 'id(00000000)'
As sample line might look like:

[id(00000000), propget, helpstring("Looks up a value in the dictionary")] VARIANT Value([in] BSTR bstrName);
You can see the default member right after the word VARIANT. In this case the default member is a property called 'Value'.

Note: Methods can also be the default member.


Article ID:   W16557
File Created: 2005:02:18:12:21:26
Last Updated: 2005:02:18:12:21:26