By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,519 Members | 2,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,519 IT Pros & Developers. It's quick & easy.

Tip - alternative to conditional compilation.

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.