S
Snaux
Multi-part Question, all short and related to VBA OOP and particularly
Object Instanciation.
1) In most OOP languages, when you instanciate an object you can pass
parameters to it: fido = New Dog(#Brown, #Cute). From what I've seen,
VBA doesn't seem to allow this (it throws an end of line error), so you
have to create a new object, then explicitly change whatever settings
were preset by your object_initialize proc. So, am I missing some
alternate command or trick to do this? I really prefer the concept of
single-line object instanciation, as it tends to limit errors by
third-party programmers, who I'm writing for.
2) In some languages, you can add a new property to an existing object
at runtime, even though the object itself doesn't necessarily know what
that property is for: fido.addProp(#BadBreath, True). Is there a way to
do this? as a workaround, I've been simply adding an "AdditionalData"
collection to all my objects, but it's a little lame to add the
overhead unless I really need it.
3) Similarly, a few OOP langs (C, Java, Flash come to mind) allow you
to redefine the native objects/methods/functions through prototyping or
direct tweaking of the object's code. VB/VBA Possible?
4) Finally, is there a way to put an external watcher on an object
property, something that executes code when the property of an object
changes, without the object itself knowing about it? This would be like
the debugger's watch function, except that instead of breaking the code
when the condition is met, it executes code. I've made some half-ass
progress using a system timer which checks for value changes
periodically, but it's cumbersome and very after-the-fact: Set
needsbath= watchdog(fido, hasfleas=true, milliseconds:=100). I'd
prefer: fido.addwatch(#fleas, #needsbath), which would simply run the
code "Needsbath" whenever the status of fido's fleas property changes
(or better yet, is ABOUT to change). Fido doesn't need to know he needs
a bath, fido's owner does.
5) CurrentDB? Got it. CurrentForm? No prob. CurrentProc? Anyone? I'd
love to be able to get the name of the currently-executing procedure,
and it's caller, into a string or addressof.
BONUS POINTS: Any good books on VB/VBA OOP?
Object Instanciation.
1) In most OOP languages, when you instanciate an object you can pass
parameters to it: fido = New Dog(#Brown, #Cute). From what I've seen,
VBA doesn't seem to allow this (it throws an end of line error), so you
have to create a new object, then explicitly change whatever settings
were preset by your object_initialize proc. So, am I missing some
alternate command or trick to do this? I really prefer the concept of
single-line object instanciation, as it tends to limit errors by
third-party programmers, who I'm writing for.
2) In some languages, you can add a new property to an existing object
at runtime, even though the object itself doesn't necessarily know what
that property is for: fido.addProp(#BadBreath, True). Is there a way to
do this? as a workaround, I've been simply adding an "AdditionalData"
collection to all my objects, but it's a little lame to add the
overhead unless I really need it.
3) Similarly, a few OOP langs (C, Java, Flash come to mind) allow you
to redefine the native objects/methods/functions through prototyping or
direct tweaking of the object's code. VB/VBA Possible?
4) Finally, is there a way to put an external watcher on an object
property, something that executes code when the property of an object
changes, without the object itself knowing about it? This would be like
the debugger's watch function, except that instead of breaking the code
when the condition is met, it executes code. I've made some half-ass
progress using a system timer which checks for value changes
periodically, but it's cumbersome and very after-the-fact: Set
needsbath= watchdog(fido, hasfleas=true, milliseconds:=100). I'd
prefer: fido.addwatch(#fleas, #needsbath), which would simply run the
code "Needsbath" whenever the status of fido's fleas property changes
(or better yet, is ABOUT to change). Fido doesn't need to know he needs
a bath, fido's owner does.
5) CurrentDB? Got it. CurrentForm? No prob. CurrentProc? Anyone? I'd
love to be able to get the name of the currently-executing procedure,
and it's caller, into a string or addressof.
BONUS POINTS: Any good books on VB/VBA OOP?