cancel
Showing results for 
Search instead for 
Did you mean: 

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

Highlighted
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
Highlighted
Community Hero

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

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
================================
Highlighted
Occasional Contributor

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

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

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

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
================================
New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to pass custom command-line arguments as a test parameter for the TechCorner tag!

Will you dare to take the challenge?


Top Kudoed Authors