Results 1 to 22 of 22

Thread: (VB6) Replicate control interface or encapsulate control into UserControl

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,987

    (VB6) Replicate control interface or encapsulate control into UserControl

    This a tool intended to ease the work of recreating the interface of a control.

    (Related project: Compare two controls interfaces)

    It creates a *.ctl file with all the basic code.

    It has two options:
    1) Encapsulate the control into the UserControl
    2) Just replicate the interface.

    Name:  RepInt4.png
Views: 562
Size:  8.6 KB


    You need to add the control that you want to replicate/encapsulate inside that zone.

    Notes:
    1) For the ones that do not want to write to the registry comment the SaveSetting line.

    2) If the control has properties or methods that are named with VB reserved words, you'll need to manually change/fix that.

    3) Also if there are properties that has indexes, you'll have to manually finish the code for storing them (ReadProperties/WriteProperties).

    4) In the *.ctl file there are saved attributes of the members of the original control, if you copy and paste the code to another UserControl you'll lose them.

    5) Some properties or parameters that are defined "As Object" may need to be changed to the proper data type, for example "As RecordSet".

    Download from GitHub.

  2. #2
    Addicted Member gilman's Avatar
    Join Date
    Jan 2017
    Location
    Bilbao
    Posts
    173

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    Great job Eduardo

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,987

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    Updated.
    Several bug fixes and improvements.

    Quote Originally Posted by gilman View Post
    Great job Eduardo
    Thank you!

  4. #4
    Fanatic Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Location
    any where
    Posts
    575

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    i just added a combobox and runed and errors,how work?
    see this test :



    same this image link : link image

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,987

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    That's strange, do you have SP6 installed?
    (in case you does) Do you have installed any other update after SP6?

    When you get the error, check the value of iMem.Name to see what property is causing it.

  6. #6
    Fanatic Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Location
    any where
    Posts
    575

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    sp6 installed,and no i dont install any update after it.
    if u think error is about sp6 send me link download you trusted.
    i checked iMem.Name it is SelStart value but i unchecked it and again same error,i unchecked step to step others too but same error.

  7. #7
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,092

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    @Black_Storm: Do you use Break on All Errors or on Unhandled only in VB6 IDE options?

    cheers,
    </wqw>

  8. #8
    Fanatic Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Location
    any where
    Posts
    575

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    Quote Originally Posted by wqweto View Post
    @Black_Storm: Do you use Break on All Errors or on Unhandled only in VB6 IDE options?

    cheers,
    </wqw>
    how can i check these? and how can i use this sample for my thread here create a activex used combox and move all methods and properties to this new control? i want find a solution for my problem

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,987

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    It is a mystery why you are getting that error.
    I'm also using SP6 and no other update aside from it.
    I tested on Windows 10/64 bits and XP-SP3/32 bits with VB6-SP6 and I do not get the error.

    You can download the latest version of this utility, you should not get any error now.

    Anyway, it would had been easy for you to overcome the problem by just adding error handling or by manually setting the current line to the next line once you got the error, being this a program that only needs to run once.

  10. #10

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,987

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    Thanks shagratt!

  12. #12
    Fanatic Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Location
    any where
    Posts
    575

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    Quote Originally Posted by Eduardo- View Post
    It is a mystery why you are getting that error.
    I'm also using SP6 and no other update aside from it.
    I tested on Windows 10/64 bits and XP-SP3/32 bits with VB6-SP6 and I do not get the error.

    You can download the latest version of this utility, you should not get any error now.

    Anyway, it would had been easy for you to overcome the problem by just adding error handling or by manually setting the current line to the next line once you got the error, being this a program that only needs to run once.
    i explained in post #6,step to step checked and same error,i cant now use this control for my thread asked here :
    create a activex used combox and move all methods and properties to this new control
    @Eduardo posted current thread for my problem and i jst checked this thread,my question is clear in my posted thread

    i am waiting to find a solution in my thread posted.

    and if any body have not error for this sample,so send me combobox full properties and events like as user control for me,i will be download here.

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,987

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    I see three options:
    1) Do what I said and download the latest version.
    2) Learn how to skip a line in the code.
    3) Forget about this utility.

  14. #14
    Fanatic Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Location
    any where
    Posts
    575

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    how can fix this error?
    i added a data combo box and i cant crate ctl file now:




    Attachment 179338

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,987

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    Ok, I simplified it, please download the new version.
    (it does not requite to manually write the ocx file any more)

  16. #16
    Addicted Member gilman's Avatar
    Join Date
    Jan 2017
    Location
    Bilbao
    Posts
    173

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    I think there's a bug in the procedure GenerateCtlCode:
    Code:
    Private Sub GenerateCtlCode()
        Dim iTLI As TypeLibInfo
        Dim c As Long
        Dim iMem As cMember
        Dim iParams As String
        Dim iParam As cParameter
        Dim p As Long
        Dim iControlName As String
        Dim iAttrPut As Boolean
        Dim iSave As Boolean
        Dim iParams2 As String
        Dim iDef As Variant
        Dim iPropsWithParams As Boolean
        
        iControlName = UserControl.ContainedControls(0).Name
        
        AddLine "Version 5.00"
        AddLine "Begin VB.UserControl My" & TypeName(UserControl.ContainedControls(0))
        If Not mHasVisibleProperty Then
            AddLine "   InvisibleAtRuntime=   -1  'True"
        End If
        If Not mHasHwndProperty Then
            AddLine "    Windowless      =   -1  'True"
        End If
        If mEncapsulate Then
            Set iTLI = TLI.TypeLibInfoFromFile(mTypeLibFile)
            AddLine "   Begin " & iTLI.Name & "." & TypeName(UserControl.ContainedControls(0)) & " " & iControlName
            AddLine "   End"
        End If
        AddLine "End"
        AddLine "Attribute VB_Name = ""My" & TypeName(UserControl.ContainedControls(0)) & """"
        AddLine "Attribute VB_GlobalNameSpace = False"
        AddLine "Attribute VB_Creatable = True"
        AddLine "Attribute VB_PredeclaredId = False"
        AddLine "Attribute VB_Exposed = False"
        AddLine "Option Explicit"
        AddLine ""
        
        ' Events
        If UBound(mEvents) > LBound(mEvents) Then
            AddLine "' Events"
            For c = LBound(mEvents) To UBound(mEvents)
                Set iMem = mEvents(c)
                iParams = ""
                For p = 1 To iMem.ParamCount
                    Set iParam = iMem.Parameters(p)
                    If iParams <> "" Then iParams = iParams & ", "
                    iParams = iParams & IIf(iParam.IsByVal, "ByVal ", "") & iParam.Name & " As " & iParam.TypeName2
                Next
                AddLine "Public Event " & iMem.Name & "(" & iParams & ")"
                PutAttr iMem
            Next
            AddLine ""
        End If
        
        ' Properties
        iSave = False
        iPropsWithParams = False
        For c = LBound(mProperties) To UBound(mProperties)
            Set iMem = mProperties(c)
            If iMem.Persistent Then
                ' property to save
                If (iMem.HasLet Or iMem.HasSet) And (iMem.HasGet) Then
                    iSave = True
                    If iMem.ParamCount > 0 Then
                        iPropsWithParams = True
                    End If
                End If
            End If
        Next
        If mEncapsulate Then
            If iSave Then
                ' property defaults contants
                AddLine ""
                AddLine "' Default property values constants"
                For c = LBound(mProperties) To UBound(mProperties)
                    Set iMem = mProperties(c)
                    
                    If iMem.HasGet And iMem.Persistent Then
                        If iMem.HasLet Then
                            If (iMem.ParamCount = 0) And (Not iMem.ReturnTypeObject) Then
                                iDef = Empty
                                On Error Resume Next
                                iDef = CallByName(UserControl.ContainedControls(0), iMem.Name, VbGet)
                                On Error GoTo 0
                                If iMem.ReturnTypeLong Then
                                    'that line launch an error if the control hasn't BackColor property
                                    iDef = CLng(UserControl.ContainedControls(0).BackColor)
                                    'I think the line would be
                                    iDef = CLng(iDef)
                                End If
                                If iMem.ReturnTypeIsNumeric Then
                                    iDef = Str$(iDef)
                                End If
                                If iMem.ReturnTypeName = "Boolean" Then
                                    iDef = CLng(CBool(iDef))
                                    If iDef = "-1" Then
                                        iDef = "True"
                                    Else
                                        iDef = "False"
                                    End If
                                End If
                                
                                AddLine "Private Const c" & iMem.Name & "_Default" & " As " & IIf(iMem.ReturnTypeLong, "Long", iMem.ReturnTypeName) & " = " & IIf(iMem.ReturnTypeName = "String", """", "") & iDef & IIf(iMem.ReturnTypeName = "String", """", "")
                            End If
                        End If
                    End If
                Next
                AddLine ""
    
    'the rest of code unchanged
    ....
    
    End Sub
    with this change, the code seems to work fine

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,987

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    Yes, sorry, I introduced that bug in the recent update. I was testing with that property and left it unintentionally.
    Thank for pointing it out.
    It is fixed now.

  18. #18

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,987

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    Important update.
    Bugs fixed, new options and improvements.

  19. #19

  20. #20

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,987

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    Quote Originally Posted by shagratt View Post
    Great Eduardo! Downloading the updated version
    Thank you. I also made another project that is related: 'Compare two controls interfaces' that can be used to test existent replacement controls for backward compatibility against the original ones.

  21. #21
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,742

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    I am developing my own simple visual form designer.How many properties does each control have?If the property is set, how to save the volume as much as possible.For example, maybe 90% of the attributes have default values, and we don't need to save them.

    .Net Framework control, I also want to encapsulate it to VB6 inside use.How many attributes does he have?
    Last edited by xiaoyao; May 12th, 2021 at 11:50 AM.

  22. #22

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,987

    Re: (VB6) Replicate control interface or encapsulate control into UserControl

    I have not idea what you are asking.

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