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.DOMDocum ent
End Type
Public Sub OALInitXMLDocum ent(oalXMLDocum ent As oaltXMLDocument )
Set oalXMLDocument. Doc = New MSXML2.DOMDocum ent
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 OALInitXMLDocum ent(oalXMLDocum ent As oaltXMLDocument )
' Set oalXMLDocument. Doc = CreateObject("M SXML2.DOMDocume nt")
'End Sub
'------
- Steve Jorgensen
----
I would have written you a shorter program,
but I didn't have the time. 2 4320
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.DOMDocum ent End Type Public Sub OALInitXMLDocum ent(oalXMLDocum ent As oaltXMLDocument ) Set oalXMLDocument. Doc = New MSXML2.DOMDocum ent 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 OALInitXMLDocum ent(oalXMLDocum ent As oaltXMLDocument ) ' Set oalXMLDocument. Doc = CreateObject("M SXML2.DOMDocume nt") '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.
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.c om... 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.DOMDocum ent End Type Public Sub OALInitXMLDocum ent(oalXMLDocum ent As oaltXMLDocument ) Set oalXMLDocument. Doc = New MSXML2.DOMDocum ent 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 OALInitXMLDocum ent(oalXMLDocum ent As oaltXMLDocument ) ' Set oalXMLDocument. Doc = CreateObject("M SXML2.DOMDocume nt") '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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 difficult to understand.
I've described it as GOTO's on steroids, and that's what it is!.
One argument against abolishing it it that it is useful for conditional
compilation when porting code, etc. Well, it seems to me C++ supports that...
|
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()
{
|
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 main()
|
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 want in there, I will not receive a
compilation error). I do get such an error in F() - because of the garbage I
intentionally put there - but F() should not compile in the first place.
Am I misusing this attribute?!
#undef DBG
|
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?
| |
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 compilation constant then I
would like the executable to be XYZ.exe and if nothing is specified
then the executable should be ABC.exe.
Any ideas appreciated.
Thanks in advance.
|
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. Feature1=true,Feature2=false, ...
VS2005 seems to either allow the existance of the constant or not.
ie. You must omit a constant not declare it to be false
This means that the list no longer declares the state of all the options.
|
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 have blocks of
code in different source files that were conditionally compiled based
on that constant. Now that C# has done away with include files, is
there any way of doing the same thing, short of defining the constant
multiple times at the head...
|
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 Python comments and is used
by default to introduce #ifdef etc. lines.
Here's an example of what I'm trying to do:
#ifdef DEBUG
stderr.write("variable is...") #details of msg omitted
#endif
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |