Ask a Question

How declare class in one unit and create class object in other unit...?

elyush
Occasional Contributor

How declare class in one unit and create class object in other unit...?

Hi,

I am using TestComplete7, wrritng code  in VBScript. an i hav such problem.



I have declare class in unit A - class MyClass

                                                    'properties and methods

                                                End Class



And then in unit B i want to  create instance of MyClass such way-  set myinstance = new MyClass.

In unit B i include unit A .

When the script run,   throws exception - "Class not defined: MyClass"

Can't i  create object instance in other unit???
3 REPLIES 3
AlexKaras
Community Hero

Hi Elya,



In unit A you should create a function that returns an instance of the class and call this function from unit B.

E.g.

' unit A

Function InitClass()

  Set InitClass = new MyClass

End Function



class MyClass

  'properties and methods

End Class





'unit B

...

Set vClass = Function InitClass()

vClass.Property = ...

intResult = vClass.Function(...)

...
Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
elyush
Occasional Contributor

Ok, thank u.. i understand..
AlexKaras
Community Hero

Oops...



Obviously instead of

'unit B

...

Set vClass = Function InitClass()



it had to be

'unit B

...

Set vClass = InitClass() ' copy-pasted 'Function' is not needed here



Sorry for the typo...
Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
cancel
Showing results for 
Search instead for 
Did you mean: