| MATLAB COM Builder | ![]() |
Creating an Instance of a Class
Before calling a class method (compiled MATLAB function), you must create an instance of the class that contains the method. Visual Basic provides two techniques for doing this:
CreateObject function
New operator
CreateObject Function
This method uses the Visual Basic application program interface (API) CreateObject function to create an instance of the class. To use this method, dimension a variable of type Object to hold a reference to the class instance and call CreateObject with the class' programmatic identifier (ProgID) as an argument as shown in the next example.
Function foo(x1 As Variant, x2 As Variant) As Variant Dim aClass As Object On Error Goto Handle_Error aClass = CreateObject("mycomponent.myclass.1_0") ' (call some methods on aClass) Exit Function Handle_Error: foo = Err.Description End Function
| Adding Events to COM Builder Objects | Visual Basic New Operator | ![]() |