-
Nov 13th, 2020, 10:17 PM
#1
(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.
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.
Last edited by Eduardo-; Mar 22nd, 2021 at 06:34 PM.
-
Nov 14th, 2020, 07:09 AM
#2
Addicted Member
Re: (VB6) Replicate control interface or encapsulate control into UserControl
-
Nov 14th, 2020, 01:18 PM
#3
Re: (VB6) Replicate control interface or encapsulate control into UserControl
Updated.
Several bug fixes and improvements.
Originally Posted by gilman
Great job Eduardo
Thank you!
Last edited by Eduardo-; Nov 14th, 2020 at 02:16 PM.
-
Nov 15th, 2020, 12:45 AM
#4
Fanatic Member
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
-
Nov 15th, 2020, 02:55 AM
#5
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.
-
Nov 16th, 2020, 12:12 PM
#6
Fanatic Member
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.
-
Nov 16th, 2020, 12:46 PM
#7
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>
-
Nov 17th, 2020, 04:13 AM
#8
Fanatic Member
Re: (VB6) Replicate control interface or encapsulate control into UserControl
Originally Posted by wqweto
@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
-
Nov 17th, 2020, 09:06 PM
#9
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.
-
Nov 17th, 2020, 09:47 PM
#10
Re: (VB6) Replicate control interface or encapsulate control into UserControl
Amazin job Eduardo!!! It will save lot of work
-
Nov 17th, 2020, 09:56 PM
#11
Re: (VB6) Replicate control interface or encapsulate control into UserControl
-
Nov 19th, 2020, 04:22 AM
#12
Fanatic Member
Re: (VB6) Replicate control interface or encapsulate control into UserControl
Originally Posted by Eduardo-
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.
-
Nov 19th, 2020, 05:59 AM
#13
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.
Last edited by Eduardo-; Nov 19th, 2020 at 06:15 AM.
-
Nov 21st, 2020, 01:47 AM
#14
Fanatic Member
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
-
Nov 21st, 2020, 05:04 AM
#15
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)
-
Nov 21st, 2020, 06:32 AM
#16
Addicted Member
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
-
Nov 21st, 2020, 06:45 AM
#17
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.
-
Mar 9th, 2021, 04:02 PM
#18
Re: (VB6) Replicate control interface or encapsulate control into UserControl
Important update.
Bugs fixed, new options and improvements.
-
Mar 11th, 2021, 04:16 PM
#19
Re: (VB6) Replicate control interface or encapsulate control into UserControl
Great Eduardo! Downloading the updated version
-
Mar 11th, 2021, 04:21 PM
#20
Re: (VB6) Replicate control interface or encapsulate control into UserControl
Originally Posted by shagratt
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.
-
May 12th, 2021, 10:23 AM
#21
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.
-
May 12th, 2021, 10:28 AM
#22
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|