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

Reply

Join Date: Mar 2007
Posts: 16
Reputation: Ved_TheOne is an unknown quantity at this point 
Solved Threads: 0
Ved_TheOne Ved_TheOne is offline Offline
Newbie Poster

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

 
0
  #1
Jan 16th, 2009
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 codes
Setting_Layer_Path Class
  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
Did  I  say  I  m  good?   Shit,  Im  a    Rembrandt
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 187
LizR LizR is offline Offline
Posting Virtuoso

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

 
0
  #2
Jan 16th, 2009
The class is not static, ergo, you cant. You would have to make an object, and then you can let it expire.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 46
Reputation: BlackSun is an unknown quantity at this point 
Solved Threads: 4
BlackSun BlackSun is offline Offline
Light Poster

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

 
-1
  #3
Jan 17th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 46
Reputation: BlackSun is an unknown quantity at this point 
Solved Threads: 4
BlackSun BlackSun is offline Offline
Light Poster

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

 
0
  #4
Jan 18th, 2009
hey i wrote in wrong thread sorry
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 46
Reputation: BlackSun is an unknown quantity at this point 
Solved Threads: 4
BlackSun BlackSun is offline Offline
Light Poster

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

 
-1
  #5
Jan 18th, 2009
no no this is the right thread sorry
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 17
Reputation: bhaskerlee is an unknown quantity at this point 
Solved Threads: 2
bhaskerlee bhaskerlee is offline Offline
Newbie Poster

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

 
0
  #6
Jan 19th, 2009
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");
}
}
}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 6468 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC