473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

referencing a class member from another file

I need to call(reference) class member
"PrintDestination.PrintDestinationPrinter" from another file. How do I
do it, I tried
"ReportRenderer.PrintDestination.PrintDestinationP rinter" but it
doesn't work. Please help!

here is my class:

*****************************************

using System;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using ABELSoft.Reporting.User.Facade;

namespace ABELSoft.Reporting.User.Facade
{
/// <summary>
/// Summary description for ReportRenderer.
/// </summary>
public class ReportRenderer
{
private CrystalDecisions.CrystalReports.Engine.ReportDocum ent
m_ReportDocument;
private string m_sReportName;
private PrintDestination m_PrintDestination;
private string m_sDestinationName;
private DataSet m_ReportData;

public void RenderReport()
{
switch( m_PrintDestination )
{
case PrintDestination.PrintDestinationScreen:
{
ReportPreviewFac Preview = new ReportPreviewFac();
Preview.ReportSource = m_ReportDocument;
Preview.ShowDialog();
break;
}
case PrintDestination.PrintDestinationPrinter:
{
m_ReportDocument.PrintToPrinter( 1, false, 0, 0 );
break;
}
case PrintDestination.PrintDestinationFile:
{
m_ReportDocument.Export();
break;
}
}
}

public enum PrintDestination
{
PrintDestinationPrinter,
PrintDestinationScreen,
PrintDestinationFile
}
#endregion public routines
}
}

Nov 17 '05 #1
1 3531
There are two ways you can do this.

(1) Compile both source files into the same binary output file.

or

(2) Reference the binary file that contains the code you need to use when
building.

Note that both of these require you to do something to the input for the
compiler.

If you are using Visual Studio .NET, here's how it will look:

(1) Make sure the two source files are in the same project. That is all.

(2) Make sure the calling project has a reference to the code being called.
Use the 'Add References' feature. In Solution Explorer, right-click on the
References item for the project that's going to call the function and select
Add References. Add a reference to the component that contains the code you
wish to call. If the component is a different project in the same solution,
add it as a 'Project' reference. Otherwise, Browse... for the DLL.
If you are using the compiler from the command line, here's how it will
look:

(1) csc SourceFile1.cs SourceFile2.cs

or

(2) csc /r:ExternalComponent.dll SourceFile1.cs

That "/r" switch is what a 'reference' in VS.NET means. It says "The code
I'm compiling now makes use of classes defined in this external DLL here".

Regardless of which of these two techniques you use, the source code will
look the same. You can either use the fully qualified name, e.g.
ABELSoft.Reporting.User.Facade.ReportRenderer.Prin tDestination.PrintDestinationPrinter,
or you can add a 'using' statement to the top of the file:

using ABELSoft.Reporting.User.Facade;

and then just refer to it as
ReportRenderer.PrintDestination.PrintDestinationPr int.

Note that the 'using' statement does not render the steps mentioned earlier
optional. You still need to do either (1) or (2). The 'using' statement is
*never* interpreted by the C# compiler as an instruction to go and look for
some external file. It simply tells it that you plan not to bother using
the full namespace every time.

By the way, in C#, it's not normal to do this:

public enum PrintDestination
{
PrintDestinationPrinter,
PrintDestinationScreen,
PrintDestinationFile
}

This looks like something a C++ developer would do. In C# we normally do
this:

public enum PrintDestination
{
Printer,
Screen,
File
}

That would be a bad idea in C++ of course because in C++, enumeration entry
names are scoped by namespace. But in C#, you never ever see the name of
an enumeration entry used in isolation. It is *required* to be referred to
via its containing enum name. So it would always be
PrintDestination.Printer, etc. Given this fact, putting the enum name in
the enum member is always redundant.
--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/

<Dj******@ABELSoft.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I need to call(reference) class member
"PrintDestination.PrintDestinationPrinter" from another file. How do I
do it, I tried
"ReportRenderer.PrintDestination.PrintDestinationP rinter" but it
doesn't work. Please help!

here is my class:

*****************************************

using System;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using ABELSoft.Reporting.User.Facade;

namespace ABELSoft.Reporting.User.Facade
{
/// <summary>
/// Summary description for ReportRenderer.
/// </summary>
public class ReportRenderer
{
private CrystalDecisions.CrystalReports.Engine.ReportDocum ent
m_ReportDocument;
private string m_sReportName;
private PrintDestination m_PrintDestination;
private string m_sDestinationName;
private DataSet m_ReportData;

public void RenderReport()
{
switch( m_PrintDestination )
{
case PrintDestination.PrintDestinationScreen:
{
ReportPreviewFac Preview = new ReportPreviewFac();
Preview.ReportSource = m_ReportDocument;
Preview.ShowDialog();
break;
}
case PrintDestination.PrintDestinationPrinter:
{
m_ReportDocument.PrintToPrinter( 1, false, 0, 0 );
break;
}
case PrintDestination.PrintDestinationFile:
{
m_ReportDocument.Export();
break;
}
}
}

public enum PrintDestination
{
PrintDestinationPrinter,
PrintDestinationScreen,
PrintDestinationFile
}
#endregion public routines
}
}

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
13
by: jt | last post by:
Being a newbie in C++ and comming from C, I can't find information on how to access a class member function outside its class. Below is a snippet of the class and its member function: look at...
11
by: Milind | last post by:
Hi, I was trying to implement a composition relation, somthing of the following type: class A { public: class B {
13
by: Duron | last post by:
I created a new folder using VS.NET 2003. Then I created a new web form under that folder, say, \Member\Default.aspx. However, even if I didn't do anything to that page, a run-time error appears...
6
by: Mikey_Doc | last post by:
Hi We are running cms 2002, Framework 1.0 with Visual studio 2002. We have just upgraded to Framework 1.1 and visual studio 2003. All of our database connection strings are stored within the...
0
by: N. Demos | last post by:
Hello, I have a custom usercontrol, of which I have two instances of in my aspx page. Both the usercontrol and page have codebehind. In the page codebehind, I want a member variable for each...
4
by: TWEB | last post by:
I think I may have an IIS / ASP.Net Configuration issue that I need some guidance with resolving. Here's the problem: a) I have a .stm file. b) I referenc a .aspx file on this .stm file using a...
12
by: titan nyquist | last post by:
I have a class with data and methods that use it. Everything is contained perfectly THE PROBLEM: A separate thread has to call a method in the current instantiation of this class. There is...
3
by: Torsten Wiebesiek | last post by:
Hi folks, currently I'm writing image classes for easier handling of Intel's IPP library. My idea is to have to different classes. One class that represents a complete image and deals with all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.