472,805 Members | 1,058 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

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 4247
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Steven T. Hatton | last post by:
I've made no secret of the fact that I really dislike the C preprocessor in C++. No aspect of the language has caused me more trouble. No aspect of the language has cause more code I've read to be...
1
by: chris han | last post by:
Hi, all, I'm trying to use Conditional Compilation Statements in my code. using System; #define DEBUG public class MyClass { public static void Main() {
12
by: wanghz | last post by:
Hi, Could I ask some questions about the conditional compilaion? Suppose I have three simple files: a.c, b.c and c.h /* --------a.c--------- */ #include <stdio.h> #include "c.h" int...
2
by: FireStarter | last post by:
Guys, in the code that follows, why does the method F() still compile, even if DBG is undefined? Inside method G(), the code inside <#if DBG> does not compile (notice that I can write whatever I...
1
by: A.M-SG | last post by:
Hi, We have a solution with several c# projects within it. How can I define solution wide conditional compilation symbols?
1
by: lavu | last post by:
Is there any way to specify a different executable name for my project based on value that I have set in my conditional compilation constant. For eg: If I have FIRST specified in my conditional...
4
by: Bob | last post by:
Hi, In VS2003 conditional compilation constants and their state could be defined at project level. I was using this to control what features where offered by various builds. i.e....
10
by: Dave | last post by:
I'm a C++ programmer of many years, trying to get my feet wet in C#. I have a question about conditional compilation. In C++, I would sometimes define a constant in an include file, and then...
6
by: maxwell | last post by:
I'm trying to use the gpp utility (Gnu points to http://en.nothingisreal.com/wiki/GPP) to do conditional compilation in Python, and I'm running into a problem: the same '#' character introduces...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.