|
-
May 30th, 2002, 01:53 PM
#1
Thread Starter
New Member
Add extra methods to objects?
Is there someone who can tell me if it's possible to add some extra methods to an object?
In other words, is it possible to create textbox1.Email and textbox1.Something?
Thanks in advance, ColdSTone
-
May 30th, 2002, 02:01 PM
#2
Frenzied Member
Yes, you can take the regular text box and create a better ActiveX control adding any methods/properties you wish.
-
May 30th, 2002, 02:04 PM
#3
Thread Starter
New Member
Ok, I understand, but how do I create that better ActiveX control?
Is there a special function for that?
Do you know a good tutorial?
ColdSTone
-
May 30th, 2002, 02:18 PM
#4
Frenzied Member
www.vbworld.com
You'll find tuturials on creating activex controls.
It's a type of project in VB.
-
May 30th, 2002, 02:32 PM
#5
Or if you just want to add some functions you can also make a 'wrapper' class. Basically you make a class that contains the added functions and a textbox and link it to an existing textbox.
VB Code:
'class code we'll name it cTxtExtender
Private WithEvents useBox as TextBox
Public Property Get Box() as TextBox
Set Box=useBox
End Proeprty
Public Sub Setup(txtbox as TextBox)'if you make this class outside of the exe then you'll have to switch it to object
Set useBox=txtbox
'now you can use that control and even receive events from it
End Sub
'add functions
Public Sub Email()
'some error handling
If useBox is nothing then
Err.Raise vbObjectError + 512, "TextBox Extender", "Textbox not set yet."
Exit Sub
End If
'add your email code here
End Sub
Private Sub Class_Terminate()
Set useBox=Nothing
End Sub
'this is the form code or how to use it
Private TxtEx as New cTxtExtender
Private Sub Form_Load()
TxtExt.Setup Text1
'to use a function
TxtExt.Email
'to access normal textbox stuff either use the textbox directly or
TxtExt.Box.Text="Hey there"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set TxtEx=Nothing
End Sub
-
May 30th, 2002, 03:04 PM
#6
Addicted Member
Very nice post from Edneeis...
I love clean and simple solutions like that...
-
Jun 2nd, 2002, 06:21 AM
#7
Thread Starter
New Member
And how about adding extra properties?
Is this possible too?
ColdSTone
-
Jun 2nd, 2002, 01:28 PM
#8
Sure but usually to access the custom properties you'd use the first level MyObject.CustomProp whereas accessing the actual textbox properties would have another level MyObject.Box.OriginalProp. Just make the properties in the class.
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
|