
Вопрос по классам ВБС
#1
Отправлено 29 апреля 2011 - 09:50
В пером юните создал класс и описал его.
В другом юните пытаюсь сделать экземпляр каласса но кидается ексепшин:
An exception occurred in the "ContactFunctions" unit at line 4:
Microsoft VBScript runtime error
Class not defined: 'Contacts'
Хотя 'USEUNIT указывал где находится описание и определение класса.
Как сделать в ТК что бы екземпляр класса можно было создавать в юните в котором этот класс не обьявлен. возможно ли это?
#2
Отправлено 29 апреля 2011 - 10:30
ТК 7ой версии, ВБС.
В пером юните создал класс и описал его.
В другом юните пытаюсь сделать экземпляр каласса но кидается ексепшин:
An exception occurred in the "ContactFunctions" unit at line 4:
Microsoft VBScript runtime error
Class not defined: 'Contacts'
Хотя 'USEUNIT указывал где находится описание и определение класса.
Как сделать в ТК что бы екземпляр класса можно было создавать в юните в котором этот класс не обьявлен. возможно ли это?
http://smartbear.com...warticle/14418/
#3
Отправлено 29 апреля 2011 - 11:42
ТК 7ой версии, ВБС.
В пером юните создал класс и описал его.
В другом юните пытаюсь сделать экземпляр каласса но кидается ексепшин:
An exception occurred in the "ContactFunctions" unit at line 4:
Microsoft VBScript runtime error
Class not defined: 'Contacts'
Хотя 'USEUNIT указывал где находится описание и определение класса.
Как сделать в ТК что бы екземпляр класса можно было создавать в юните в котором этот класс не обьявлен. возможно ли это?
http://smartbear.com...warticle/14418/
The ODT.Classes property returns the Classes object that holds a collection of classes created via the ODT project item.
Класс я делал не через ОДТ, а просто класс... в ВБС
#4
Отправлено 29 апреля 2011 - 12:24
VBScript allows you to define and use custom classes in your script code. However, in TestComplete’s VBScript projects, you can create class instances only in the same script unit where the class is defined. Creating a class instance in another unit causes an error. The following code demonstrates the issue:
VBScript [UnitA] Class MyClass ... End Class Sub TestRoutine ... ' Creating class in the same unit Set cls = New MyClass ' OK! ... End Sub [UnitB] 'USEUNIT UnitA Sub AnotherRoutine ... ' Creating class in another unit Set cls = New MyClass ' Error! ... End Sub
To solve the problem, you can create a helper routine in the unit, in which the class is defined. This routine will create a class instance and return it. You can then call this routine from another unit and work with the created class instance in a usual manner:[UnitA] Class MyClass ... End Class ' This routine creates and returns a new class instance Function GetClassInstance Set GetClassInstance = New MyClass End Function [UnitB] 'USEUNIT UnitA Sub AnotherRoutine ... ' Calling a routine defined in UnitA. ' Do not forget to include this unit with the USEUNIT statement Set cls = GetClassInstance ' OK ! ... End Sub
Количество пользователей, читающих эту тему: 1
0 пользователей, 1 гостей, 0 анонимных