943,917 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 19705
  • C# RSS
Jan 16th, 2009
0

[how to]Call functions of one Class from another class

Expand Post »
Hello,

I know it may be silly to ask this

but I m stuck with this: so please help

I have two classes in the same namespace

Quote ...
1. Setting_Layers_Path class files
Which helps in establishing connection to the layers(GIS connections). It contains number of functions which return an object of specific datatype

2. Form Class
Now, what I want to do is on Form_Load Event I want to call all the functions present in the Setting_Layer_Path class

One way of doing is by creating object of the Setting_Layer_Path Class and working with the functions within it

Can someone tell me, is there any other way of calling the functions directly without creating object

Attach is the codes
Setting_Layer_Path Class
C# Syntax (Toggle Plain Text)
  1. namespace RELGIS_DT_Load_Calculation
  2. {
  3. public sealed class Setting_Layers_Path
  4. {
  5. #region User Defined Variables
  6. IMxDocument pMxDoc;
  7. IMap pMap;
  8. #endregion
  9. public Setting_Layers_Path()
  10. {
  11. }
  12. private static IFeatureLayer get_DivsionFeatureLayer()
  13. {
  14. return null;
  15. }
  16. private static IFeatureLayer get_SubDivisionFeatureLayer()
  17. {
  18.  
  19. }
  20. private static IFeatureLayer get_EHVStnFeatureLayer()
  21. {
  22.  
  23. }
  24. private static IFeatureLayer get_SubStnFeatureLayer()
  25. {
  26. return CommonGISFunc.FirstFeatureLayerWithMN(pMap, "AU_SUBSTATION");
  27. }
  28.  
  29. private static IFeatureLayer get_DistributedTransformerFeatureLayer()
  30. {
  31. return CommonGISFunc.FirstFeatureLayerWithMN(pMap, "DISTRIBUTIONTRANSFORMER");
  32. }
  33. }
  34. }


Form frmDT_selection.cs
namespace RELGIS_DT_Load_Calculation
{
    public partial class frmDT_selection : Form
    {
        #region variable declaration
        IMxDocument pMxDoc;
        #endregion

        public frmDT_selection(IApplication m_app)
        {
            InitializeComponent();
        }       

        private void frmDT_selection_Load(object sender, EventArgs e)
        {
            //This is where i want to call the functions of the Setting_Layers_Path class without creating an object
        }

Any help would be deeply appreciated

Thanks in advance
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ved_TheOne is offline Offline
16 posts
since Mar 2007
Jan 16th, 2009
0

Re: [how to]Call functions of one Class from another class

The class is not static, ergo, you cant. You would have to make an object, and then you can let it expire.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Jan 17th, 2009
-1

Re: [how to]Call functions of one Class from another class

this is claa example
[/code=c#]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DaniWebtest3
{
class time
{
public static void GetIt()
{
MessageBox.Show(DateTime.Now.ToString());
}
}
}
[/code]

so u must declar ur methode public static this means that only the class will acceses this function and u will not create instance for ur class .
read this :
http://msdn.microsoft.com/en-us/libr...s3(VS.80).aspx

bye
Reputation Points: 28
Solved Threads: 5
Light Poster
BlackSun is offline Offline
46 posts
since Feb 2008
Jan 18th, 2009
0

Re: [how to]Call functions of one Class from another class

hey i wrote in wrong thread sorry
Reputation Points: 28
Solved Threads: 5
Light Poster
BlackSun is offline Offline
46 posts
since Feb 2008
Jan 18th, 2009
-1

Re: [how to]Call functions of one Class from another class

no no this is the right thread sorry
Reputation Points: 28
Solved Threads: 5
Light Poster
BlackSun is offline Offline
46 posts
since Feb 2008
Jan 19th, 2009
0

Re: [how to]Call functions of one Class from another class

Make the methods as Public Static.Then you can call the methods using the classname itself without creating obect.

namespace RELGIS_DT_Load_Calculation
{
public sealed class Setting_Layers_Path
{
#region User Defined Variables
IMxDocument pMxDoc;
IMap pMap;
#endregion
public Setting_Layers_Path()
{
}
public static IFeatureLayer get_DivsionFeatureLayer()
{
return null;
}
public static IFeatureLayer get_SubDivisionFeatureLayer()
{

}
public static IFeatureLayer get_EHVStnFeatureLayer()
{

}
public static IFeatureLayer get_SubStnFeatureLayer()
{
return CommonGISFunc.FirstFeatureLayerWithMN(pMap, "AU_SUBSTATION");
}

public static IFeatureLayer get_DistributedTransformerFeatureLayer()
{
return CommonGISFunc.FirstFeatureLayerWithMN(pMap, "DISTRIBUTIONTRANSFORMER");
}
}
}
Reputation Points: 12
Solved Threads: 3
Newbie Poster
bhaskerlee is offline Offline
19 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Pass value to another form
Next Thread in C# Forum Timeline: Automatially move data





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC