Sie sind auf Seite 1von 27

Imprint

© 2004 innotec GmbH


Issued by: innotec GmbH
Eisenwerkstraße 1
D-58332 Schwelm
http://www.innotec.de
Comos is a product of innotec GmbH.
The software and hardware designations mentioned in this manual are, in
most cases, also registered trade marks and as such are subject to statutory
regulations.
Comos® is the registered trade mark of innotec GmbH.
This manual is protected by copyright laws. All rights, even those including
translation, reprint and duplication, be it partially or in whole, are reserved.
No part of the documation may be reproduced, distributed or processed using
electronic systems, copied or disseminated in any form whatsoever
(photocopy, microfilm or a different process), also not for teaching purposes,
without the written consent of the publisher.
The Comos license is linked to the license floppy disk and the related adapter
(dongle). Loss of the license floppy disk or adapter (dongle) automatically
leads to loss of the license.
For any questions in connection with the documentation, please contact:
Dokumentation@innotec.de.

Comos Hotline Support:


Monday-Friday between 08:30 and 17:00
Phone: +49 (0) 228 6480 577

Quickstart Developer PR81E01 Status: November 21, 2005

© innotec GmbH
© innotec GmbH
Connecting or extending Comos externally Starting Comos via the command line

1 Connecting or extending Comos externally


1
1.1 Starting Comos via the command line
The direct start is not taken into consideration if there is a correct command
line available.

Parameters
The following parameters can be included in any order to the Comos call:

comos.exe /? Shows this help.


/D (Database name) (D = database)
Opens the specified database.
/U [0,1,2] (U = User)
Uses the specified user to log into the database:
0 (default): Default access of the user
1: Universal access
2: Alternative access for the user
/P (Project name) (P = Project)
Opens the specified project.
/V (V = View)
Read-only mode (view mode).
/E Use of a specific Comos ET license.
/PID Use of a specific Comos P&ID license.
/NO Turns off the startup animation.

Example
Comos /D z:\ReleaseDatenbank\Comos.mdb /P SO1 /NO

Screens:1 and Screens:2


Specifies the number of screens used. Primarily used as a special solution for
Windows 2000, which cannot automatically detect the number of screens.

© innotec GmbH 1-1


Starting Comos externally: XIF Connecting or extending Comos externally

1 Old technology
As an alternative to the above, you can also work with parameters separated
by spaces. In that case you must follow a specific order:

1. Parameter [complete database file name with directory]


2. Parameter [0: Default access; 1: Universal access;
2: Alternative access for the user]
3. Parameter [Project name]

Example:
Comos.exe z:\ReleaseDatenbank\Comos.mdb 1 SO1

This older form should not be mixed with the use of parameters.

1.2 Starting Comos externally: XIF

1.2.1 XIF.exe

The DOS program XIF.exe is in the bin directory of Comos.

1.2.1.1 Call under DOS or VB

XIF can start Comos via an external program call, it can open a project, select
an object in the Navigator, and open a report on which the selected object has
been placed.

Parameters

/MD: V View mode


/MD: NO NO: No Comos animation on startup
/DB: Database type
/DB: ACCESS, SQL, ORACLE

/DN: Database name / data source ODBC


/DN: C:\Comos_DB\ComosPT.MDB

/PR: Project name


/PR: H001

1-2 © innotec GmbH


Connecting or extending Comos externally Starting Comos externally: XIF

/ID: Object- systemUID


/ID: A17XK7X4K0 1
/ON: Alternative to /ID: Object ID(FullLabel)
/ON: @U2-Test Arbeitsbereiche1

/PA: Symbol type (= diagram type) of the document to be


opened
/PA: DETAIL; /PA: RI2 ...

/DT: Data type of the database. Replaces the /DB and /DN
parameters for Server databases; you get the data type
from workset.initString, for example:
/DT: [SQL - SERVER]PT_SQL_SERVER_1

/ST: Object system types as described in the documentation


"Comos Kernel", Examples for Device; CDevice
/ST: 8 ; /ST: 13 ...

/US: User name (login) after workset.CurrentUser.Name


/US: Frank

Examples
XIF.exe /MD: V /DB: ACCESS /DN: C:\Comos_DB\ComosPT.MDB /PR:
H001 /ON: =PM09FA00.EM02;Auto /PA: DETAIL

XIF.exe /DB: SQL /DN: PT_SQL_SERVER /PR: U002 /ID: A17XK7X4K0


/PA: DETAIL

Application examples
• Search for object by FullLabel
The device or document being searched for can also be identified by means
of the FullLabel. However, the FullLabel does not take folders or
prefixes into consideration. If a document is searched for by means of
FullLabel and not found, then all the parallel folders are now searched
automatically to see whether the object can be found. In addition, any
possible prefixes are also considered.
• Open a report
An object can be placed on multiple reports. For that reason you can now
input in addition the /PA: <Symbol type> option. This allows you to input
a specific report type onto which the object in question is placed. Please note
that in this case the object may not be placed on two reports of the same
type.

© innotec GmbH 1-3


Starting Comos externally: XIF Connecting or extending Comos externally

1 If no document was found (the object is not placed on a report of this type or
the symbol type is unknown), the Properties window of the object then opens.
You can also use this function in a targeted way if the Properties window is
to be opened explicitly by simply entering an unknown symbol type as the
option.

1.2.1.2 Call under C (script for WinCC)

In the following example, first the string is dimensioned (char


ASString[250]) and then a variable is prepared, within which the Comos
SystemUIDs can be created (char SystemUID[20]).
WinCC-specific settings follow: The "if-else" block is used to track down
errors. Please note that the UIDs are, of course, just examples. There are other
UIDs in your database. In the "if" line there is a different UID from those in
the next two following "else" lines (otherwise the entire "if-else" block would
be meaningless). With real data you will certainly be managing thousands, if
not tens of thousands, of objects (such as signals), "if-else" loops make no
sense in such a case and thus have to be replaced by a suitably advanced form
of error trapping.
After that the string that was dimensioned in the first line ("strcpy") is made
up. All the switches described in PARAMETERS can be used exactly so and are
appended here to the string ("strcat").
The string stored in "ASString" is then passed to the "ProgramExecute"
command. ProgramExecute first of all finds in the string the calling up of
XIF and executes it with the following parameters.
{
char ASString[250] ;
char SystemUID[20];

if (GetTagBit("U2") == 1)
strcpy( SystemUID, "/ID: C1D45BO8U7 " );
else if (GetTagBit("Error") == 1)
strcpy( SystemUID, "/ID: A1D9VBO5U7 " );
else
strcpy( SystemUID, "/ID: A1D9VBO5U7 " );

strcpy( ASString, "C:\\Programme\\Comos\\Bin\\XIF.exe " );


strcat( ASString, "/DB: ACCESS ");
strcat( ASString, "/DN: C:\\Comos_DB\\ComosPT.MDB " );
strcat( ASString, "/PR: CeBIT " );
strcat( ASString, SystemUID );
strcat( ASString, "/PA: DETAIL" );

1-4 © innotec GmbH


Connecting or extending Comos externally Own VB components for Comos

ProgramExecute( ASString );
}
1
1.2.2 XIF.init

Configure Comos window


Comos can note the window status and window position to use these the next
time that it starts.
The text "vbNormal" can be entered into the XIF.Init procedure in the last
optional Reserved parameter to achieve this. The result: Comos does not
come up maximized. Initially Comos appears centered in 2/3 of the screen,
and after that according to the saved values.

1.3 Own VB components for Comos

1.3.1 Basic commands

The following steps demonstrate the core points of the access. Obviously a
workable VB project will still require all sorts of extensions, such as more
variables, error trapping, and the like. The following brief illustration thus
does not necessarily imply that error trapping, for example, can be dispensed
with.
1. Set reference to VB project
The dialog for the component references is opened in Visual Basic.
Search for "comos.dll" and link it. The entry "Comos Kernel " appears
in the dialog window.
2. Set and create topmost object
The "workset" is the entry object in the Comos object hierarchy:
Dim m_wset As IComosDWorkset
Afterwards the object still has to be created in the usual way:
Set m_wset = CreateObject("COMOS")

3. Open database
If you give the "Init" command with two blank parameters (which are
only of interest for advanced developers), you can open the database very
easily in this way:
m_wset.Init("","",<<Data base name>>)

© innotec GmbH 1-5


Own VB components for Comos Connecting or extending Comos externally

1 4. Fetch and set user


"GetAllUsers" is the Comos command to open the list of users; you can
find a specific user with "Item". Thus CurUserName is a string acting as
a variable for the name of the user:
Set User = m_wset.GetAllUsers.Item(CurUserName)
However, this has not yet set the user, the setting must be done explicitly:
m_wset.SetCurrentUser User

5. Fetch and set project


The two following steps are synonymous with fetching and setting the
user. Please note that the prerequisite for fetching and setting the project
is that you have first fetched and set a user. The desired project is fetched
with ProjName as the name of the project
Set CurProj = m_wset.GetAllProjects.Item(ProjName)
m_wset.SetCurrentProject CurProj

From this point on you can work in the usual way. For example, you can work
as if you were using the object debugger: you can set an object and then call
up the functions from it.

1.3.2 Programming the Comos Properties window in VB

Sample file
<comos>\Help\English\Further Documentation\Comos general\
ComosFormInterface.zip

In this zip file there is an example as to how the Properties windows of devices
can be integrated into Comos. The example assumes that you have a sound
knowledge of VB.

Overview
The following information applies solely to the creation of Properties win-
dows. In addition, there are still other extension options for Comos, such as
the creation of PlugIns or your own attributes.
The basic steps for the integration of new Properties windows are as follows:
1. Creation of a VB project
A ProgID is also allocated within the VB project.

1-6 © innotec GmbH


Connecting or extending Comos externally Own VB components for Comos

Set the references within the VB project:


comos.dll
The entry "Comos Kernel " appears in the dialog window.
1
ivbcomos.dll
The entry "ComosVBInterface " appears in the dialog window. All the
main classes, ENums and the like originate from this file.
XStdMod.dll
This component primarily gets the default Comos error handler. If you
wish to use your own error handler, you can do without XStdMod.dll.
2. Program the Properties windows as indicated in the following.
There are the following in the ComosVBInterface:
IEditForms
This class must be implemented. IEditForms gets among other things
three functions that simulate certain pseudo-events. More on this later.
ENums of the interface versions
The ENums are in an interface description. Within the components
themselves only the version numbers of the interfaces are called up, but
not changed. The version management only covers the Comos interfaces.
More on this later.
IEditFormsEventHandler
If you wish to react to "Events" yourself.
3. Enter the ProgID in the base data
CDevice, on the Configuration tab
A tab is added if you input a ProgID here.
CDevice, on the System tab
The entire Properties window of the device is replaced if you input a
ProgID here.

Comments on the example


1. Controls
Begin VB.UserControl Example
In this example two text boxes are created with which you could change the
name and description of any Comos object (underneath the workset).
2. Implement the basic structure
2.1IEditForms
Implements ComosVBInterface.IEditForms
All the interfaces must have implemented the "IEditForms" class.

© innotec GmbH 1-7


Own VB components for Comos Connecting or extending Comos externally

1 IEditForms has among other things the important task of getting three stan-
dard functions for the simulation of "events":

Abort Button [Abort], the button with a cross [X] in the window
frame.
Apply Button [Apply].
Ok Button [OK].

The developer is not forced to use these three standard functions. The three
functions can also be left blank without any code. However, the developer
must click once on the functions so that they are actually entered in the code.
Reason: All the Properties windows of devices in Comos make use at least of
the three controls [Abort ], [Apply ] and [OK ] (and the button with the cross
that reacts in the same way as [Abort ]). Since these three functions are man-
datorily implemented, this makes the software considerably more stable: there
would be an error when the controls were triggered if these functions did not
exist. However, nothing happens because these pseudo-events (the functions
Abort, Apply and Ok) are implemented, but blank.

2.2IEditFormsEventHandler
If the components are regularly to react to events initiated by other compon-
ents, there must be an additional login as event handler:
Implements ComosVBInterface.IEditFormsEventHandler

For simplicity, this implementation was not given in the code examples in file
ComosFormInterface.zip. It is as follows: Comos.exe accepts the actual Win-
dows events and informs IEditFormsEventHandler when one of them has been
triggered.
In IEditFormsEventHandler the following Windows events are allocated to six
standard functions:
OnAbort Button [Abort], area with a cross[X] in the window
frame.
OnApply Button [Apply].
OnChange Process that can be saved ("change").
Thus, for example, the [Apply] button is set to activated.

1-8 © innotec GmbH


Connecting or extending Comos externally Own VB components for Comos

OnClose Complete termination of a component.


Thus OnClose takes place later than OnAbort. OnClose
is recommended, for example, if a Properties window is
1
opened from a list by means of |New and the Properties
window is then aborted. If you were to react here in the
list to OnAbort, the component would not have been fully
unloaded yet and this could lead to incomprehensible
messages.
OnOk Button [OK].
OnSelectChan If selections in lists were changed.
ge

Thus in the following the developer has nothing more to do with the Windows
events but instead works with functions that operate the relevant specific
events. Thus it is also left up to the developer to allocate the above-mentioned
functions to self-defined pseudo-events, for example, to keyboards com-
mands or mouse menus.
Only for completeness, it needs to be said that similarity of the names of some
of the functions does not in any way change the basic fact that they are indeed
different functions.
Thus, for example, in IEditForms there is an Abort and in IEditFormsEvent-
Handler there is an OnAbort. Both functions fulfill similar tasks, namely to
function as pseudo-events, but are nonetheless not identical.
The topic of "Events" is covered further in item 5.
3. Versions
Fundamentally speaking, in software development there is the problem that a
component can also be developed once this is already in production use. The
problem then arises that the components of a program must know in commu-
nication what the functional scope (interface) the other components have.
This problem is resolved in Comos with a "version". In IEditFormsEventHand-
ler there are the following lines for this purpose:

Function GetVersion() As Long

The corresponding point in the sample code is:


Private Function IEditForms_GetVersion

© innotec GmbH 1-9


Own VB components for Comos Connecting or extending Comos externally

1 The versions concerned involve versions of the Comos interfaces. The list of
the relevant version numbers of the Comos interfaces is thus embedded in the
customer component with GetVersion and so Comos knows which actual
component version this third-party component belongs to.
If the publics are defined in the third-party component and these in turn are
used in further third-party components, the developer himself is responsible
for interface management. Comos does not know the publics of the third-party
components.
4. Input / Output
m_EnableChange, m_ExampleObject, m_ItemObjects
Here the objects are passed to the component. In this example you can then
change the name and description of these objects.
5. Events
If you wish to get "events" (trigger them yourself), then write the following:
Private Sub IEditForms_EventsHandlerAdd

Only now is it permitted to get other component "events":


Private Sub txtDescr_Change()
...
m_EventsHandlers.Item(i).OnChange Me

But it is also important to log off again there:


Private Sub IEditForms_EventsHandlerRemove

The typical case: the component is unloaded and then no longer needs to be
logged in to the event handler.
6. Tabs
m_Partners
All the properties areas together of a device make up a collection. You can tell
from the Configuration tab of the CDevice which properties areas there can
be: all the entries of the first level are areas that could be a "partner". For
example, that could be the tabs. But the "general area" above the tabs is also
a "partner" of this type. Note also with the Specification tab that all the Spe-
cification tabs held there and all the attributes belong to this one partner.
These collections are managed with:
Private Property Get IEditForms_Partners
and
Private Property Let IEditForms_Partners

1-10 © innotec GmbH


Connecting or extending Comos externally Own VB components for Comos

and
Private Property Set IEditForms_Partners 1
7. Start mode
m_StartMode
Currently there are two start modes:
MainMenu: if the component is called up from the Comos menu
Default: in all other cases
8. ProgID
Private Property Get IEditForms_ProgID
The ProgID is not set here but in the VB project instead. The ProgID is fixed
in the code here and thus can only be fetched with a Get.
9. Hold the component in the background
Private Sub IEditForms_ShowMode
If a device is closed, for example, then not everything is necessarily unloaded.
Instead you can also set the component to be invisible and then you can access
it again more quickly if you need to later.
10. Error handler
ComosStdErrorHandler:
StdErrorHandler Err, Modulename, "Sub IEditForms_Apply"

This is the standardized Comos error handler. You can of course write your
own one instead.

1.3.3 Creating and integrating your own attributes

Sample file
<comos>\Help\English\Further Documentation\Comos general\
ComosSpecification.zip

In this zip file there is an example of how you can integrate your own attribu-
tes into Comos. The example assumes that you have a sound knowledge of
VB.

Overview
1. Create a VB project

© innotec GmbH 1-11


Own VB components for Comos Connecting or extending Comos externally

1 Set the references in the VB project:


comos.dll
The entry "Comos Kernel " appears in the dialog window.
XStdMod.dll
This component primarily gets the default Comos error handler. If you
wish to use your own error handler, you can do without XStdMod.dll.
2. Program an attribute as indicated below.
xxx.pag
Define your own PropertyPage.
xxx.ctl
Write the actual logic of the attribute and create the control.
3. Input the attribute in OCXCONTROLS

Comments on the example


1. Controls
Begin VB.UserControl SUITest
In this example a text box whose you can set is created.
2. Basic structure
Private m_Specification As IComosDSpecification

Attributes must of course use the Comos object of an attribute. The Comos
object permanently saves the information in the database.
The attribute itself is normally written to the ctl file as for a control.
The display and capabilities of the attribute can be set via an extra Property-
Page, of which there will be more later.
3. Declaring and managing your own control properties
In addition, you can define properties for the display of the control. The cor-
responding interface for it is the so-called "PropertyPage".
If you use a PropertyPage of this type, you can additionally allow the user to
change the default properties of the control (font, size, etc.).
However, the PropertyPage is primarily required if the attribute is to possess
special display properties. An example of this would be the Comos "List"
attribute, which has a whole of extra properties over and above those of the
default control properties.

1-12 © innotec GmbH


Connecting or extending Comos externally Own VB components for Comos

This distinguishes the attributes of the Properties windows of the device: there
the user is not allowed to change the default properties or to define his own
properties and to then allow these to be changed by the user.
1
The amended properties are stored in the PropBag of VB:
m_MyProperty = PropBag.ReadProperty("MyProperty", 0)

In addition to the examples given above, a PropertyPage (namely, the access


to the attribute via the properties of the display) also provides a good way to
make it possible to manage the attributes. You could define various forms of
logic and then provide a simple checkbox in the properties of the display that
the administrator can use to enable or disable them. In this way you could then
activate one or other form of behavior of the attribute.
If you do not wish to allow or make use of any of the above techniques, you
can simply dispense with the above line. You likewise then do not need the
lines in which the properties are set.
4. Managing and storing user inputs
Public Property Set Specification(ByVal vNewValue As Object)
Set m_Specification = vNewValue

Private Sub Text2_Change()


RaiseEvent Change

The inputs of the user are accepted and written to the Comos object. You are
of course tied to the properties and methods that are made available by ICo-
mosDSpecification, see the "Comos Kernel" documentation.

5. Special capabilities of Comos attributes


Public Function RefreshValue()
The "Update values" mouse command can be selected on the Specification tab
on the Devices page. This updates all the attributes of the tab that had been
implemented in the corresponding code of the above function. The function
can be left blank but may not be deleted.
Public Property Let ShowSpecName
When in display mode the mouse commands "All attributes |Display names"
and "All attributes |Display description" can be selected on the Specification
tab. This public property toggles it.

Integrate attribute
Attributes are selected via "Display type". If you wish to use your own attri-
bute, you must therefore create and integrate your own display type.

© innotec GmbH 1-13


Own VB components for Comos Connecting or extending Comos externally

1 The following list is used to regulate which types of display of attributes are
recognized by Comos:
System project, @System |OCXCONTROLS.
Comos has an internal list of attributes. This internal list takes effect if the
OCXCONTROLS does not exist or has been corrupted. However, OCXCONTROLS
takes priority over the internal list.
OCXCONTROLS is not in the Release database and must be created by yourself
as required. You can restrict yourself to the desired additional lines in such a
case. It is not necessary then to enter all the attributes in this list.
Structure of OCXCONTROLS:

Name ProgId of the SuiControl, e.g. "ComosSUIxxx.SUIxxx"


Description Description that is to be displayed in the Combobox on
the Properties page of the attribute.
Value Sequential number

1.3.4 Programming your own PlugIns

Sample file
<comos>\Help\Deutsch\Sonstige Dokumentation\Comos Allgemein\
ComosPlugIn.zip

In this zip file there is an example of how you can integrate your own PlugIns
into Comos. PlugIns are independent forms that can be started within Comos
and communicate with Comos via a fixed defined interface. PlugIns offer
somewhat more design freedom than does creating a Properties window for a
device: Properties windows assume and require that IEditForms is imple-
mented and that a number of overall conditions are complied with. There are
no such restrictions when designing a PlugIn. PlugIns are made available to
the user by means of their own icon bar. The example assumes that you have
a sound knowledge of VB.

Overview
1. Create a VB project

1-14 © innotec GmbH


Connecting or extending Comos externally Own VB components for Comos

The prerequisite is that the project name of the Class-Module must always
start with "CPlugIn", since this text is used as a search string to find
entries in the Registry. All the entries that are found in the Registry, are
1
then automatically allocated to the PlugIns menu bar in Comos.exe when
the user activates the | LOAD PLUGINS menu item.
Set the references in the VB project:
ivbcomos.dll
The entry "ComosVBInterface " appears in the dialog window. In
particular, this component gets the interfaces with which the PlugIn
communicates with Comos.
XStdMod.dll
This component primarily gets the default Comos error handler. If you
wish to use your own error handler, you can do without XStdMod.dll.
2. Program the PlugIn as indicated below.
container
Fixed definition, is not changed.
prototype.frm
The form calls up the container and carries the customer OCX.
xxx.ocx
The customer OCX. Please note that a default is not implemented via
IEditForms, as opposed to the Properties windows. The customer takes
the responsibility for the standard controls ([OK], [Abort], [Apply]) and
also the underlying logic (undo, save, etc.)
xxx.cls
Contains the actual logic.
3. All components of the project are renamed.
In principle you only need to replace all the places in which the text "Proto-
Type" occurs.
4. Prepare the bitmap
Ensure that the names match.
The bitmap (16x16 bmp file) must have the same name as the PlugInDLL and
be located in parallel with the DLL (thus as a rule in Ocx\CPlugIns).

Commenting the example


1. frmProtoType.frm

© innotec GmbH 1-15


Own VB components for Comos Connecting or extending Comos externally

1 The form is not allowed to have a border style, because the container still has
to be loaded around this form and the container brings its own border with it:
Friend Property Set Container

Otherwise the form calls up the OCX:


Begin ComosPlugInOcx.PlugInOcx PlugInOcx
...

Private Sub Form_Resize()


PlugInOcx.Left = 0

Of course, any other name is permitted as well.


2. ProtoType.cls
Implements ComosVBInterface.CXInterface
Implements ComosVBInterface.CXInterfaceEx
It is essential to implement this interface for communication with Comos.
Private Function CXInterface_GetVersion() As Long
The version management of the Comos interface is loaded here. See -->
Kapitel 3. Versions for an explanation on how this has been applied to the
Properties windows of devices.
Private Sub CXInterface_OnFormShow(ByVal Comos As Object,
ByVal Project As Object, ByVal PLTObject As Object)
The interface transfers the workset and the project as objects. If you require
these, you only need to reactivate the lines that had been commented out. This
thus saves you the effort of programming for yourself the form of access intro-
duced in →SECTION 1.3.1: BASIC COMMANDS.
3. PlugInOcx.ctl, PlugInOcx.vbp, PlugInOcx.ocx
Here is the OCX that is called up from the form.

1.3.5 Create a separate TIFF-printer interface

User-defined revision printer


The Comos printer interface can be accessed from outside. This allows you to
use and edit the output of the revision as desired. For example the revised file
can be transferred to a document management system. The interface is known
as:
..\comos\ocx\interfaces\ivbcomos.dll;
Interface: IRevisionPrinter

1-16 © innotec GmbH


Connecting or extending Comos externally Own VB components for Comos

IrevisionPrinter has the following methods:


Private Function IRevisionPrinter_AppendFile
(ByVal SrcFullFileName As String,
1
ByVal TrgFullFileName As String)
As Boolean

Private Function IRevisionPrinter_DoPrint


(ByVal Doc As Plt.IComosBaseObject,
ByVal Revision As Plt.IComosDDevice,
Optional ByVal Folder As String,
Optional ByVal Filename As String)
As Boolean

Private Property Get IRevisionPrinter_Extension() As String


Private Function IRevisionPrinter_InitPrnSettings() As Boolean
Private Function IRevisionPrinter_SetPrnDefaults() As Boolean

The user can develop his or her own DLL and make use of Comos functions
in the DLL. An example of a Visual Basic project is found under
Help\Deutsch\Sonstige Dokumentation\Comos allgemein\
UserDefRevPrn.zip

Make sure the drop-down menu in the Project options is set to User-defined
and make sure you enter the ProgID in the lower field.
ProgID = Name of the VB-project + . + class name.

1.3.6 Comos test environment for VB

1.3.6.1 Integrating Comos startup into a separate test environment

Comos possesses a dll that can be used to startup Comos in any test environ-
ment:
<Comos directory>\OCX\startup.dll
Set the reference in the VB Project menu:
PROJECT | REFERENCES, and select “Comos StartUp “

Startup.dll
• Property Comos As IComosDWorkset
The Comos object hierarchy, starting with Workset, is available, see the
documentation Comos Kernel.

© innotec GmbH 1-17


Own VB components for Comos Connecting or extending Comos externally

1 • Sub DatabaseOpen()
Opens the “Open Database“ window for database registration.
• Function ExecuteCommandline(CommandLine As String) As Long
It is equivalent to a direct start or a Comos startup via the command line.
• Sub ProjectOpen()
Opens the “Open Database“ window for database registration, and then
opens the “Open Project“ window and finally opens a window for
Working-layers (if working layers are available).
• Sub Terminate()
Terminates Workset, Comos and the application, in which Comos is being
executed. Thus this command should not be used in a pure test environment;
in this case the application is Visual Basic. In other words: this command
will stop entire VB application in a test environment.

Components to be test
Additional components are of course required for a functioning test environ-
ment. The Startup.dll only provides you with the Comos-login, nothing
more than that.
For example, a Navigator (ProjTree) and a few fields to retrieve information
from devices can be placed on a Form. The device can be accessed starting
from Workset, which is in the Startup.dll.

Here is an example:
Dim gStartUp As ComosStartUp.StartUp
Dim gWS As IComosDWorkset

Private Sub Command2_Click()


If gStartUp Is Nothing Then
Set gStartUp = New ComosStartUp.StartUp
End If
gStartUp.ProjectOpen
Set gWS = gStartUp.Comos
If Not gWS Is Nothing Then
ProjTree1.SetProject gWS.GetCurrentProject
End If
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As


Integer)
ProjTree1.ShutDown
If Not gWS Is Nothing Then

1-18 © innotec GmbH


Connecting or extending Comos externally Own VB components for Comos

gWS.Terminate
End If
Set gWS = Nothing
1
Set gStartUp = Nothing
End Sub

Additional information:
ProjTree1is the Comos component
<Comos directory>\OCX\Projtree.ocx
These components must of course be placed on a Form. The Command2_Click
command button initializes the Navigator placed in the test environment with
the currently selected project.
The Sub Form_QueryUnload terminates the test environment. The Terminate
for Workset called here is not the same as the Terminate in the Startup.dll
(since the latter one will terminate the application as well).

1.3.6.2 Old Test-OCX


Please note: this Test-OCX will no longer be maintained.
<Comos>\ocx\Debug\Testumgebung\group.vbg

The VB project contains two forms.


FormStart.frm

The above is the known dialog for database registration. After selecting the
database, the [COMOS LOGIN]
button is to be clicked.
The drop-down list Project (Working Overlay) now gets initialized. Open the
list and view the projects,
followed by the corresponding working layers of the project.

© innotec GmbH 1-19


Accessing DLLs in a Comos script Connecting or extending Comos externally

1 The [Next] command button opens the project and the next form Frm-
Test.frm:

The OCX that was used to explain the properties technique for devices is
shown on the right, see also →SECTION 1.3.2: PROGRAMMING THE COMOS PROPERTIES
WINDOW IN VB.

The command button [CONTROL INIT/REFRESH] includes the current selection


from the Functree links into the OCX.
Any entry in the control will be temporarily automatically included by the
object in the Functree.
No saving processes occur.

1.4 Accessing DLLs in a Comos script


You can access DLLs with the aid of the CreateObject function.

1.4.1 Example 1: Call via an attributes script

Goal
In the following example the product and the median value of three attributes
is to be determined with the aid of an own DLL. The result is output on the
same tab in the attributes specified for it.

1-20 © innotec GmbH


Connecting or extending Comos externally Accessing DLLs in a Comos script

Creating a sample DLL


1. A new DLL is created in VB through the | FILE | NEW PROJECT
| ACTIVEX DLL menu item. In the following example the DLL is given the
1
name ComosMathFunc. (This DLL is thus not supplied as standard with
Comos.)
2. The DLL ComosMathFunc is given the class MathFuncCls.
3. The class MathFuncCls is given the two functions Product() and
MedianValue()
Public Function MedianValue(Val1 As Double, Val2 As Double,
Val3 As Double) As Double
MedianValue = (Val1 + Val2 + Val3) / 3
End Function
Public Function Produkt(Val1 As Double, Val2 As Double, Val3
As Double) As Double
Product = Val1 * Val2 * Val3
End Function

Create sample base data

Spec1, Spec2, Spec3


Attribute Display type : input field
Name / description: Spec1/Spec1, ...
Product
Attribute Display type : input field
Name / description: Spec4 / Product
Median value
Attribute Display type : input field
Name / description: Spec5 / median value

© innotec GmbH 1-21


Accessing DLLs in a Comos script Connecting or extending Comos externally

1 Calling up a DLL in the script of the attributes


Calling up this DLL is done via event OnChange of attributes Spec1 , Spec2
and Spec3 .
An object of class MathFuncCls is created in this script with the help of the
expression
set Calculation = CreateObject("ComosMathFunc.MathFuncCls")

Sub OnChange()
'After editing the unit or the value
Dim Spec1, Spec2, Spec3, Spec4, Spec5
Dim Calculation

set Spec1 = Specs.TD.Spec1


set Spec2 = Specs.TD.Spec2
set Spec3 = Specs.TD.Spec3
set Spec4 = Specs.TD.Spec4
set Spec5 = Specs.TD.Spec5
if (Spec1.Value <> "") AND (Spec2.Value <> "") AND
(Spec3.Value <> "") Then
set Calculation = CreateObject("ComosMathFunc.MathFuncCls")
Spec4.Value = Calculation.Product(CInt(Spec1.Value),
CInt(Spec2.Value),CInt(Spec3.Value))
Spec5.Value = Calculation.MedianValue(CInt(Spec1.Value),
CInt(Spec2.Value),CInt(Spec3.Value))
else
Spec4.Value = ""
Spec5.Value = ""
end if
End Sub

1.4.2 Example 2: Script block of the PrintManager

This example makes use of a standard component of Comos: the Document-


Manager.dll.
Sub Action(Query, QueryBrowser)
Set DocColl = WorkSet.GetTempCollection

Set SelObjs = QueryBrowser.SelectedObjects


For i = 1 to SelObjs.Count
Set ObjItem = SelObjs.Item(i)
If Not ObjItem Is Nothing Then
If ObjItem.SystemType = 29 Then
'Insert the other queries here...
'to extract the matching document...
DocColl.Append ObjItem

1-22 © innotec GmbH


Connecting or extending Comos externally Accessing DLLs in a Comos script

End If
End If
Next
1
msgbox doccoll.count
Set DocMgr =
CreateObject("ComosDocumentManager.DocumentManager")
DocMgr.PrintDocuments DocColl
'Then select the appropriate PDF printer and print and
print...
End Sub

This script is entered in the script block of PrintManager and prints out the
documents from the selected entries.

© innotec GmbH 1-23


Accessing DLLs in a Comos script Connecting or extending Comos externally

1-24 © innotec GmbH

Das könnte Ihnen auch gefallen