468,136 Members | 1,406 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,136 developers. It's quick & easy.

Tip - alternative to conditional compilation.

To begin with an example...

Let's say you were wanting to write code usign early binding to the MSXML
library, but then be able to switch between early and late binding at will.
Conditional compilation is one possibility, but it's not practical.

1. You have to put a precompiler condition block around every Dim and
every function declaration that might need to change,
2. If the code spans multiple modules, the flags have to be changed in all
modules to make the switch.
3. Conditional compilation is reported to cause problems if you ever want
or need to use the /DECOMPILE switch.

It turns out you can better encapsulate what needs to be changed in cases
like this by wrapping an object variable in a user-defined data type, then
write all your code to pass around data using the object variable type, and
reference methods and properties via the element in the variable. It works
across module boundaries, the code change is small and only needs to be
made in one place in the code, and the compiler automatically takes care of
treating method/property references as early/late bound depending on the
custom type declaration.

Example:
--------
' Uncomment the following code to use a project reference to the MS XML
library.
'------
Public Type oaltXMLDocument
Doc As MSXML2.DOMDocument
End Type
Public Sub OALInitXMLDocument(oalXMLDocument As oaltXMLDocument)
Set oalXMLDocument.Doc = New MSXML2.DOMDocument
End Sub
'------

' Uncomment the following code to use late-bound references to the MS XML
' library and not require a project reference.
'------
'Public Type oaltXMLDocument
' Doc As Object
'End Type
'Public Sub OALInitXMLDocument(oalXMLDocument As oaltXMLDocument)
' Set oalXMLDocument.Doc = CreateObject("MSXML2.DOMDocument")
'End Sub
'------
- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.
Nov 12 '05 #1
2 3977
Correction...

On Mon, 01 Sep 2003 07:05:55 GMT, Steve Jorgensen <no****@nospam.nospam>
wrote:
To begin with an example...

Let's say you were wanting to write code usign early binding to the MSXML
library, but then be able to switch between early and late binding at will.
Conditional compilation is one possibility, but it's not practical.

1. You have to put a precompiler condition block around every Dim and
every function declaration that might need to change,
2. If the code spans multiple modules, the flags have to be changed in all
modules to make the switch.
3. Conditional compilation is reported to cause problems if you ever want
or need to use the /DECOMPILE switch.

It turns out you can better encapsulate what needs to be changed in cases
like this by wrapping an object variable in a user-defined data type, then
write all your code to pass around data using the object variable type, and - should read "using the user defined variable type" -reference methods and properties via the element in the variable. It works
across module boundaries, the code change is small and only needs to be
made in one place in the code, and the compiler automatically takes care of
treating method/property references as early/late bound depending on the
custom type declaration.

Example:
--------
' Uncomment the following code to use a project reference to the MS XML
library.
'------
Public Type oaltXMLDocument
Doc As MSXML2.DOMDocument
End Type
Public Sub OALInitXMLDocument(oalXMLDocument As oaltXMLDocument)
Set oalXMLDocument.Doc = New MSXML2.DOMDocument
End Sub
'------

' Uncomment the following code to use late-bound references to the MS XML
' library and not require a project reference.
'------
'Public Type oaltXMLDocument
' Doc As Object
'End Type
'Public Sub OALInitXMLDocument(oalXMLDocument As oaltXMLDocument)
' Set oalXMLDocument.Doc = CreateObject("MSXML2.DOMDocument")
'End Sub
'------
- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.

- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.
Nov 12 '05 #2
Steve,
Now it makes sense, I was puzzled by your first posting.

Of course you could always wrap them up in your own classes as well.

Terry

"Steve Jorgensen" <no****@nospam.nospam> wrote in message
news:0k********************************@4ax.com...
Correction...

On Mon, 01 Sep 2003 07:05:55 GMT, Steve Jorgensen <no****@nospam.nospam>
wrote:
To begin with an example...

Let's say you were wanting to write code usign early binding to the MSXML
library, but then be able to switch between early and late binding at will.Conditional compilation is one possibility, but it's not practical.

1. You have to put a precompiler condition block around every Dim and
every function declaration that might need to change,
2. If the code spans multiple modules, the flags have to be changed in allmodules to make the switch.
3. Conditional compilation is reported to cause problems if you ever wantor need to use the /DECOMPILE switch.

It turns out you can better encapsulate what needs to be changed in cases
like this by wrapping an object variable in a user-defined data type, thenwrite all your code to pass around data using the object variable type, and
- should read "using the user defined variable type" -
reference methods and properties via the element in the variable. It

worksacross module boundaries, the code change is small and only needs to be
made in one place in the code, and the compiler automatically takes care oftreating method/property references as early/late bound depending on the
custom type declaration.

Example:
--------
' Uncomment the following code to use a project reference to the MS XML
library.
'------
Public Type oaltXMLDocument
Doc As MSXML2.DOMDocument
End Type
Public Sub OALInitXMLDocument(oalXMLDocument As oaltXMLDocument)
Set oalXMLDocument.Doc = New MSXML2.DOMDocument
End Sub
'------

' Uncomment the following code to use late-bound references to the MS XML
' library and not require a project reference.
'------
'Public Type oaltXMLDocument
' Doc As Object
'End Type
'Public Sub OALInitXMLDocument(oalXMLDocument As oaltXMLDocument)
' Set oalXMLDocument.Doc = CreateObject("MSXML2.DOMDocument")
'End Sub
'------
- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.

- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Steven T. Hatton | last post: by
1 post views Thread by chris han | last post: by
12 posts views Thread by wanghz | last post: by
2 posts views Thread by FireStarter | last post: by
4 posts views Thread by Bob | last post: by
10 posts views Thread by Dave | last post: by
6 posts views Thread by maxwell | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.