954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

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

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 codesSetting_Layer_Path Class

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

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


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:)

Ved_TheOne
Newbie Poster
16 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

The class is not static, ergo, you cant. You would have to make an object, and then you can let it expire.

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 

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/library/79b3xss3(VS.80).aspx

bye

BlackSun
Light Poster
46 posts since Feb 2008
Reputation Points: 28
Solved Threads: 5
 

hey i wrote in wrong thread sorry

BlackSun
Light Poster
46 posts since Feb 2008
Reputation Points: 28
Solved Threads: 5
 

no no this is the right thread sorry :D

BlackSun
Light Poster
46 posts since Feb 2008
Reputation Points: 28
Solved Threads: 5
 

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");
}
}
}

bhaskerlee
Newbie Poster
19 posts since Dec 2008
Reputation Points: 12
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You