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

function passing / inheritice ?

hi,

Im new to C# - ive have my background in c/c++ - and somethings are abit new
to me, so havent really gotten the total feel of the laguage yet.

I have a situation which i really have no idea to solve in c# - what i do,
is that i have a MAIN form, which subsequently calls several other forms.

There are very few variable things between each form, but i need to have a
"SaveData()" function for each form.

In C++ it was possible to do this by inheratice of classes - in C i could
pass a functionpointer to my local function, and obtain the thing i wish.

How do i do a similar thing i c# ? - pass some reference to a local function
(in one class) to another class ?

Hope you can help.
Nov 16 '05 #1
7 1010
dtdev:

You can have a base class which has the SaveData() function.

All other forms can inherit the base class with the common SaveData or other
common functions.

You can also override the SaveData function in each Form depending on
whether you want to implement the same functionality or use a variation of
it.

Thanks
--
data mining and .net team
http://www.visual-basic-data-mining.net/forum
"dtdev" <no*****@spamnotx.it> wrote in message
news:O9****************@TK2MSFTNGP12.phx.gbl...
hi,

Im new to C# - ive have my background in c/c++ - and somethings are abit new to me, so havent really gotten the total feel of the laguage yet.

I have a situation which i really have no idea to solve in c# - what i do,
is that i have a MAIN form, which subsequently calls several other forms.

There are very few variable things between each form, but i need to have a
"SaveData()" function for each form.

In C++ it was possible to do this by inheratice of classes - in C i could
pass a functionpointer to my local function, and obtain the thing i wish.

How do i do a similar thing i c# ? - pass some reference to a local function (in one class) to another class ?

Hope you can help.

Nov 16 '05 #2
Hi,

You would typically do that sort of thing with inheritance in C# too. Create
a new baseclass that inherits from System.Windows.Forms.Form and then let
all your other forms inherit from that baseclass instead of the default
System.Windows.Forms.Form.

In the baseclass you can implement the Save() method.

--
Patrik Löwendahl - C# [MVP]
cshrp.net - 'Elegant code by witty programmers'
cornerstone.se - 'IT Training for proffessionals'

"dtdev" <no*****@spamnotx.it> wrote in message
news:O9****************@TK2MSFTNGP12.phx.gbl...
hi,

Im new to C# - ive have my background in c/c++ - and somethings are abit new to me, so havent really gotten the total feel of the laguage yet.

I have a situation which i really have no idea to solve in c# - what i do,
is that i have a MAIN form, which subsequently calls several other forms.

There are very few variable things between each form, but i need to have a
"SaveData()" function for each form.

In C++ it was possible to do this by inheratice of classes - in C i could
pass a functionpointer to my local function, and obtain the thing i wish.

How do i do a similar thing i c# ? - pass some reference to a local function (in one class) to another class ?

Hope you can help.

Nov 16 '05 #3
hi guys,

Thanks for your quick answers.

Do you know anywhere where there might be an example of this on the internet
? - just to make sure im getting it right from the start.
Nov 16 '05 #4
Check MSDN.COM for Inheritance, Object Oriented Programming (OOP) examples,
etc.

It is really not that complex :)

--
data mining and .net team
http://www.visual-basic-data-mining.net/forum
"dtdev" <no*****@spamnotx.it> wrote in message
news:OV**************@TK2MSFTNGP15.phx.gbl...
hi guys,

Thanks for your quick answers.

Do you know anywhere where there might be an example of this on the internet ? - just to make sure im getting it right from the start.

Nov 16 '05 #5
Yeah okay i guess its like in C++ so youre right ;)

Thanks ;)

"http://www.visual-basic-data-mining.net/forum" <si******@gmail.com> skrev i
en meddelelse news:eP**************@TK2MSFTNGP14.phx.gbl...
Check MSDN.COM for Inheritance, Object Oriented Programming (OOP) examples, etc.

It is really not that complex :)

Nov 16 '05 #6
C# is very similar to C++. Just tidier.
Nov 16 '05 #7

public class BaseForm : System.Windows.Forms.Form
{
public virtual void SaveData()
{
// do some saving...
}
}
public class MammothForm : BaseForm
{

public void doFunkyStuff_click(object sender, EventArgs e)
{
base.SaveData();
// - or -
this.SaveData();
// same, same but different ;)
}
}

public class MammothEatingForm : BaseForm
{

public override void SaveDate()
{
// Save data elswhere
}

public void eatAMammoth_click(object sender, EventArgs e)
{
this.SaveData();
// - not equal to -
base.SaveData();
}

}
"dtdev" <no*****@spamnotx.it> wrote in message
news:OV**************@TK2MSFTNGP15.phx.gbl...
hi guys,

Thanks for your quick answers.

Do you know anywhere where there might be an example of this on the internet ? - just to make sure im getting it right from the start.

Nov 16 '05 #8

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

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
8
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
2
by: collinm | last post by:
hi i got some error with parameter my searchFile function: char *tmp; int size; ....
14
by: Mr Newbie | last post by:
I am often in the situation where I want to act on the result of a function, but a simple boolean is not enough. For example, I may have a function called isAuthorised ( User, Action ) as ?????...
22
by: Andrew Poelstra | last post by:
int gets_ws (char *buff, int maxlen, int sc, FILE *fh); This function reads up to maxlen characters from fh, stopping when it encounters whitespace, sc, or EOF. If EOF is encountered, the...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
12
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.