Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

VB6: Forms as parameters

Options
  • 02-09-2003 10:04am
    #1
    Registered Users Posts: 7,468 ✭✭✭


    '// This is the code that calls the class method below
    Private Sub Command2_Click()
    Dim frm As Object
    
        mobjTemp.ShowReportForm (Me)
        
    End Sub
    
    '// This is the Class method being called (seperate project)
    Public Sub ShowReportForm(Parent As Object)
    
        If Not IsNull(Parent) Then
            '// mvarParentForm is type Form
            Set mvarParentForm = Parent '// Type mismatch error here
        End If
        
        frmTemp.Show vbModal, mvarParentForm
    
    End Sub
    

    I'm trying to pass a form to a method in a DLL. The method is above, I'm passing the form as an object as I can't use private object modules and trying to cast it to mvarParentForm which is giving me a Type mismatch error.

    I remember doing this before and I am returning Forms as Objects with functions. What am I doing wrong? :mad:


Comments

  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Originally posted by Evil Phil
    What am I doing wrong?

    What I'm doing wrong is casting. Previously I left the variable declared as type Object as an Object, here I'm explicitly casting it to type Form. I need to do this so Parent can take ownership of frmTemp.

    I don't think this can be done...


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Maybe you could try changing your Command2_Click code to read :
    Private Sub Command2_Click()
    Dim frm As Object
        frm = Me
        mobjTemp.ShowReportForm (frm)
        
    End Sub
    

    I don't think that this is your problem though.

    Also...again working from memory (no VB6 on this machine)....if you can live with the performance-hit of late-binding, then don't try casting the Object back to a form at all. Just leave it as an object, but call the appropriate methods as though it were a form.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Yes, calling the methods using late binding is what I would normally do. This time around I need to use the form itself as a parent form to display the new form modally (spl?)i.e. vbModal so Object won't work.

    I've already tried your code too, didn't work. I do have another way of achieving the same results but it's not a *nice*.


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    In vb6, does setting the parent for modality actually do anything, other than determining where startup=centerOwner forms will appear (which is easy functionality to reproduce) ???

    Also, from vague memory, a modal form in VB is - at a minimum - applicationally modal (i.e. it takes focus in preference to all existing forms, not just its parent).

    I'm just asking, cause all I ever did was
    myForm.show vbModal
    

    Even if this is coming from a DLL, I seem to recall that it should still be modal across what is effectively the "application space" which would include any forms from the .exe which is calling the .DLL.

    Or am I talking complete horse???

    jc


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    No, not horse. It is applicationally modal. There are times when I need it modal only to one form but I can't do that can I? Cos, as you have said, it's across the application space. Blast and double blast. I'm sure it can be done with some API trickery though.


  • Advertisement
  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Phil...

    a quick webby turned up this link which was a simple hack for doing it :

    http://www.vb-helper.com/howto_semi_modal.html

    It would appear to be from a relatively early version of VB (centering the form by hand), but if it works it should still do the trick for you.

    It seems to work fine, but if you click on the parent of hte modal form while the modal is displayed, I'm getting a funny "flickering" effect on the icon in the taskbar.

    You might be able to live with that tho?

    jc


Advertisement