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

referencing a class member from another file

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


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.