473,385 Members | 1,863 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,385 software developers and data experts.

Call function

Hello Group,

In my application I have few class, and I want call function with "master
class". This is as master form (startClass) and option window (ClassA). My
question is how call function from startClass in classA?

public startClass : System.Windows.Forms.Form
{
static void Main()
{...}
public string Function1()
{...}
private callClassA()
{
ClassA classA = new ClassA();
classA.ShowDialog();
}
}

public ClassA : System.WIndows.Forms.Form
{
private void Fuction11()
{
//call Function1();
}

}

Thx PawelR
Nov 16 '05 #1
2 10166
There may be an easier way, but....

This depends on whether Function1() uses any member variables or calls other
methods in startClass. If it doesn't, then Function1() probably should be
moved into a Global class and made static.

If it does call other methods, then you could have a reference of it in your
child ClassA:
in ClassA have the following:

System.Windows.Forms.Form _parent = null;

public System.Windows.Forms.Form Parent
{
set
{
_parent = value;
}
}

// then you can call public methods on parent
public function example ()
{
if ( _parent == null )
return;

_parent.Function1();
}

Finally, in startClass, change to the following:

private callClassA()
{
ClassA classA = new ClassA();
classA.Parent = (System.Windows.Forms.Form)this;
classA.ShowDialog();
}

"PawelR" <pa************@poczta.onet.pl> wrote in message
news:Oa**************@TK2MSFTNGP10.phx.gbl...
Hello Group,

In my application I have few class, and I want call function with "master
class". This is as master form (startClass) and option window (ClassA). My
question is how call function from startClass in classA?

public startClass : System.Windows.Forms.Form
{
static void Main()
{...}
public string Function1()
{...}
private callClassA()
{
ClassA classA = new ClassA();
classA.ShowDialog();
}
}

public ClassA : System.WIndows.Forms.Form
{
private void Fuction11()
{
//call Function1();
}

}

Thx PawelR

Nov 16 '05 #2

"PawelR" wrote...
In my application I have few class, and I want call function
with "master class". This is as master form (startClass) and
option window (ClassA). My question is how call function from
startClass in classA?


There are in practice two ways of doing it. The first is to make Function1
"static", i.e. a "class-member" instead of an "instance-member"

In that case you can call it from any object with:

startClass.Function1();

However, that's not what I'd recommend, and would need Function1 to deal
with only static members itself, and my guess is that it wouldn't be
appropriate in your case.

The other way and what I'd recommend is to send a reference of the instance
of startClass to the ClassA upon instantiation.

Example:

public StartClass : System.Windows.Forms.Form
{
static void Main()
{...}
public string Function1()
{...}
private callClassA()
{
// Send a reference of this
// upon instantiation of ClassA

ClassA classA = new ClassA(this); // <--
classA.ShowDialog();
}
}

public ClassA : System.WIndows.Forms.Form
{
// We need an instance member of StartClass
// to be able to reference it

StartClass parent = null;

// We modify the constructor to receive
// a reference to the StartClass instance

public ClassA(StartClass parent) : base()
{
this.parent = parent;
}

private void Fuction11()
{
// And then we can call it...
parent.Function1(); // <--
}

}

----------

Notice that I also capitalized the name of startClass to StartClass, as
that's the common practice of naming classes.

// Bjorn A
Nov 16 '05 #3

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

Similar topics

4
by: mangi03 | last post by:
Hi, I came acrosss g++ compile errors whenever I make a function call by reference and found out from the test program that compiler is treating the function argument differently when another...
3
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: ...
4
by: Dave | last post by:
I have a program that I've written a class for. I need to call the function in the program from the class. When I try to call the function I receive the error, the name xxx does not exist in the...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
11
by: yangsuli | last post by:
i want to creat a link when somebody click the link the php script calls a function,then display itself :) i have tried <a href=<? funtion(); echo=$_server ?>text</a> but it will call the...
46
by: Steven T. Hatton | last post by:
I just read §2.11.3 of D&E, and I have to say, I'm quite puzzled by what it says. http://java.sun.com/docs/books/tutorial/essential/concurrency/syncrgb.html <shrug> -- NOUN:1. Money or...
0
by: Mike S | last post by:
I've seen examples of using the CallWindowProc Windows API function to call functions through their addresses in VB6 -- a clever workaround to emulate C-like function pointer semantics. A...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.