473,795 Members | 3,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ShowDial og();
}
}

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

}

Thx PawelR
Nov 16 '05 #1
2 10207
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.Functio n1();
}

Finally, in startClass, change to the following:

private callClassA()
{
ClassA classA = new ClassA();
classA.Parent = (System.Windows .Forms.Form)thi s;
classA.ShowDial og();
}

"PawelR" <pa************ @poczta.onet.pl > wrote in message
news:Oa******** ******@TK2MSFTN GP10.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.ShowDial og();
}
}

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.Func tion1();

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.ShowDial og();
}
}

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(StartCla ss parent) : base()
{
this.parent = parent;
}

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

}

----------

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
3396
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 function call funcRet()is made which returns the expected argument type for the function call by reference funcByRef(class A&); The only way to get around this probelm is to first call the funcRet(), assign its value to a variable and pass that...
3
4062
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: oIE.Document.Forms("searchform").Item(<name>).Value = <myvalue> But I cannot control a dropdown with an onchange event. I can set the dropdown's value and selectedIndex, but then calling the onChange() or Click() does not do anything. It only seems to fire the onchange if I
4
2857
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 class or namespace. Where xxx is the function being called. How do I call the function?
13
4151
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 sense to punch out from managed code to native code (I was using IJW) in order to do some amount of floating point work and, if so, what that certain amount of floating point work was approximately. To attempt to do this I made a program that...
5
6543
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 new to VB.NET, so I need some help. Here is a code snippit :
11
11537
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 function whether i click the link then i tried this (using forms)
46
3864
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 property bequeathed to another by will. 2. Something handed down from an ancestor or a predecessor or from the past: a legacy of religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF, from ML legatia, from L legare, to depute, bequeath....
0
5416
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 well-known example is the use of CallWindowProc to call a function gotten via LoadLibrary/GetProcAddress. For example, I've seen code similar to the following which can register/unregister a COM DLL where the path to the DLL is known only at runtime -- in...
9
3277
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 function are of type int. (My question has nothing to do with the definition of the function foo, so don't bother about it.) If I call the function as: foo(2,3,4,5,6,7,8);/*More arguments than expected*/
6
5932
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 or without parms. I know that any function that is passed to Eval() must be declared Public. It can be a Sub or Function, as long as it's Public. I even have it where the "function" evaluated by Eval can be in a form (class) module or in a standard...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.