
2-4 Objects
2-4
tread type or model number.
2.2.1 Object Hierarchy
The path that is followed to get to a specific property may
involve several objects. The path and structure of objects is
referred to as the object hierarchy. In Visual Basic the properties
and methods of an object are accessed by hooking together the
appropriate objects through a dot operator (.) function. Each dot
operator in the object hierarchy is a function call. In many cases
it is beneficial to reduce the number of calls by setting
intermediate object variables.
For instance, expanding on our previous example involving the
car, suppose there existed an object called Car and you wanted
to set the value of its engine size. You could approach the
problem in one of two ways.
If the Engine size is a property you wanted to access quite often
in your code, using the indirect method of specification may be
easier as it reduces the amount of code thereby reducing the
possibility of error.
2.2.2 HYSYS Type Library
In order to do anything with objects it is first necessary to know
what objects are available. When an application is exposed for
Automation, a separate file is usually created that lists all the
objects and their respective properties and methods. This file is
called the type library and nearly all programs that support
Automation have one of these files available. With the help of an
Object Browser, such as the one built in to MS Excel, you now
have a way to view all the objects, properties, and methods in
Direct specification of object property
Car.Engine.Size = 4
Indirect specification of object property
Dim Eng1 as Object
Set Eng1 = Car.Engine.Size
Eng1 = 4
Komentáře k této Příručce