CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Calling methods of Dynamically Created ActiveX Control.

    I have created a usercontrol which has a Function Display which simply returns a string. I could instantiate the Activex control by using the following code

    Dim ctrl As Control
    Dim str As String
    Set ctrl = Me.Controls.Add("DispProj.DispControl", "Dispproj")
    ctrl.Visible = True

    str = ctrl.Display ' this line gives the error-438

    But when I try to call the Display method I am getting a Runtime Error-438
    (ErrDescription:The object doesn't support this method or property). Then
    I tried to call Display method by using the "CallByName" function, but it didn't work.

    Finally I attemped to create the Control Dynamically by using the CreateObject function. CreateObject is creating the instance of the object but it is not showing the control on the form. But surprisingly I could call the Display method.

    Please help me.



  2. #2
    Join Date
    Aug 1999
    Location
    Chennai(INDIA)
    Posts
    11

    Re: Calling methods of Dynamically Created ActiveX Control.

    Dynamically adding control(Not Control Array) to a form is one of the new feature of VB6. In this case we Use
    ME.Controls.Add
    to add control to the form.
    Here we are storing Reference to the Control in a Variable.

    So to Invoke A Method of this control,which is dynamically Created Use the Statement
    CallByName
    Which is new in VB6.

    Refer MSDN for syntax of CallByName.

    Regards,


    VMK

    (Sent Your comments to [email protected])





  3. #3
    Join Date
    May 1999
    Posts
    45

    Re: Calling methods of Dynamically Created ActiveX Control.

    That is correct. You can not call the display method of the control. You are getting reference of the correct object but you assigning it to ctl, which is a variable of the type control. Display is not method of class "control" however visible is a property of class "control". So you get that error for method but not for property.

    Dim obj as Object
    Dim ctrl As Control
    Dim str As String
    Set ctrl = Me.Controls.Add("DispProj.DispControl", "Dispproj")
    ctrl.Visible = True

    str = ctrl.Display() ' error not method of class Control

    str = CallByName (ctrl, "Display", VbMethod) ' should work

    Set obj = ctrl
    str = obj.Display() ' will also work & same as call by name.

    Set obj = nothing ' will not destroy control. reduce reference count.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured