473,491 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do I use a class, when the class requires functions in the main form?

I'm using visual studio 2003. I have much of my code in my main form,
called 'frmMain'.

When I create a class to perform string ops and such, it sometimes
needs to refer to functions in the main form.

However, when I use "inherits frmMain" in the class, as soon as I try
to build/run the program it gives me a System.stack overflow error. No
other indication of what's wrong.

Is this bad programming practice, or is there another way to refer to a
function in the main form?

Any help would be greatly appreciated.

Jun 7 '06 #1
7 1184
Bmack500 wrote:
I'm using visual studio 2003. I have much of my code in my main form,
called 'frmMain'.

When I create a class to perform string ops and such, it sometimes
needs to refer to functions in the main form.

However, when I use "inherits frmMain" in the class, as soon as I try
to build/run the program it gives me a System.stack overflow error. No
other indication of what's wrong.

Is this bad programming practice, or is there another way to refer to a
function in the main form?

Any help would be greatly appreciated.

Pass a reference to the main form, and declare those functions as
public. Or, put the functions in another class, and pass the class to
the new class.

T
Jun 7 '06 #2
RMT

Yes very bad. The string ops class should be self-contained, ie. the main
form should execute methods on it, not the other way around.

If you really must do this, then give the string ops class a property called
m_MainForm or pass it into the method. However, this is not very OOP, it's
more Visual Basic 6.

"Bmack500" <br********@gmail.com> wrote in message
news:11**********************@h76g2000cwa.googlegr oups.com...
I'm using visual studio 2003. I have much of my code in my main form,
called 'frmMain'.

When I create a class to perform string ops and such, it sometimes
needs to refer to functions in the main form.

However, when I use "inherits frmMain" in the class, as soon as I try
to build/run the program it gives me a System.stack overflow error. No
other indication of what's wrong.

Is this bad programming practice, or is there another way to refer to a
function in the main form?

Any help would be greatly appreciated.

Jun 7 '06 #3
Can you show me how to do the first - pass a reference to the main
form? Pardon my ignorance, I've just had to learn on the fly and could
really use formal training!

tomb wrote:
Bmack500 wrote:
I'm using visual studio 2003. I have much of my code in my main form,
called 'frmMain'.

When I create a class to perform string ops and such, it sometimes
needs to refer to functions in the main form.

However, when I use "inherits frmMain" in the class, as soon as I try
to build/run the program it gives me a System.stack overflow error. No
other indication of what's wrong.

Is this bad programming practice, or is there another way to refer to a
function in the main form?

Any help would be greatly appreciated.

Pass a reference to the main form, and declare those functions as
public. Or, put the functions in another class, and pass the class to
the new class.

T


Jun 7 '06 #4
Okay, I've put: Inherits frmMain in the class. For some reason, I'm not
getting the stack overflow now.
So is this an example of what I should not do? I can do without the
functions, but I need access to a structure I've declared that holds
program configuration info derived from an XML file I've created.

Bmack500 wrote:
Can you show me how to do the first - pass a reference to the main
form? Pardon my ignorance, I've just had to learn on the fly and could
really use formal training!

tomb wrote:
Bmack500 wrote:
I'm using visual studio 2003. I have much of my code in my main form,
called 'frmMain'.

When I create a class to perform string ops and such, it sometimes
needs to refer to functions in the main form.

However, when I use "inherits frmMain" in the class, as soon as I try
to build/run the program it gives me a System.stack overflow error. No
other indication of what's wrong.

Is this bad programming practice, or is there another way to refer to a
function in the main form?

Any help would be greatly appreciated.

Pass a reference to the main form, and declare those functions as
public. Or, put the functions in another class, and pass the class to
the new class.

T


Jun 7 '06 #5
RMT

Well what methods do you have on this class?

Public Class myClassThatUsesMainForm

Public Sub doSomethingWithMainForm ( byval theForm as frmMain )

End Sub

Public Sub doSomethingelseWithMainForm ( byval theForm as frmMain)

End Class

Public Class frmMain

....
....
Public Sub DoingSomething ()

...

Dim myThing as new myClassThatUsesMainForm

myThing.doSomethingWithMainForm ( Me )

....

End Sub

End Class
"Bmack500" <br********@gmail.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
Okay, I've put: Inherits frmMain in the class. For some reason, I'm not
getting the stack overflow now.
So is this an example of what I should not do? I can do without the
functions, but I need access to a structure I've declared that holds
program configuration info derived from an XML file I've created.

Bmack500 wrote:
Can you show me how to do the first - pass a reference to the main
form? Pardon my ignorance, I've just had to learn on the fly and could
really use formal training!

tomb wrote:
> Bmack500 wrote:
>
> >I'm using visual studio 2003. I have much of my code in my main form,
> >called 'frmMain'.
> >
> >When I create a class to perform string ops and such, it sometimes
> >needs to refer to functions in the main form.
> >
> >However, when I use "inherits frmMain" in the class, as soon as I try
> >to build/run the program it gives me a System.stack overflow error. No
> >other indication of what's wrong.
> >
> >Is this bad programming practice, or is there another way to refer to
> >a
> >function in the main form?
> >
> >Any help would be greatly appreciated.
> >
> >
> >
> Pass a reference to the main form, and declare those functions as
> public. Or, put the functions in another class, and pass the class to
> the new class.
>
> T

Jun 7 '06 #6
Thanks, you've answered my question. I need to improve my OOP
knowledge; I'll try to encapsulate the class so that it doesn't need
anything from the main form, and I'll set properties on the class to
use for the config info.

RMT wrote:
Well what methods do you have on this class?

Public Class myClassThatUsesMainForm

Public Sub doSomethingWithMainForm ( byval theForm as frmMain )

End Sub

Public Sub doSomethingelseWithMainForm ( byval theForm as frmMain)

End Class

Public Class frmMain

...
...
Public Sub DoingSomething ()

...

Dim myThing as new myClassThatUsesMainForm

myThing.doSomethingWithMainForm ( Me )

....

End Sub

End Class
"Bmack500" <br********@gmail.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
Okay, I've put: Inherits frmMain in the class. For some reason, I'm not
getting the stack overflow now.
So is this an example of what I should not do? I can do without the
functions, but I need access to a structure I've declared that holds
program configuration info derived from an XML file I've created.

Bmack500 wrote:
Can you show me how to do the first - pass a reference to the main
form? Pardon my ignorance, I've just had to learn on the fly and could
really use formal training!

tomb wrote:
> Bmack500 wrote:
>
> >I'm using visual studio 2003. I have much of my code in my main form,
> >called 'frmMain'.
> >
> >When I create a class to perform string ops and such, it sometimes
> >needs to refer to functions in the main form.
> >
> >However, when I use "inherits frmMain" in the class, as soon as I try
> >to build/run the program it gives me a System.stack overflow error. No
> >other indication of what's wrong.
> >
> >Is this bad programming practice, or is there another way to refer to
> >a
> >function in the main form?
> >
> >Any help would be greatly appreciated.
> >
> >
> >
> Pass a reference to the main form, and declare those functions as
> public. Or, put the functions in another class, and pass the class to
> the new class.
>
> T


Jun 7 '06 #7
BMack,

Mostly you create an extra form like this.

dim frm as new Form2
if you do than
frm.Owner = me

Than you can use in your form2 class
Directcast(me.owner, frmMain).Textbox1.Text = "Hello"
to put by instance "Hello" in that textbox on frmMain.

Don't understand the "me" wrong. In the frmMain class tells it that it is
that class, while in the form2 class that it is the form2 class.

In my idea is this one of the easiest solutions for your problem.

I hope this helps,

Cor

"Bmack500" <br********@gmail.com> schreef in bericht
news:11**********************@h76g2000cwa.googlegr oups.com...
I'm using visual studio 2003. I have much of my code in my main form,
called 'frmMain'.

When I create a class to perform string ops and such, it sometimes
needs to refer to functions in the main form.

However, when I use "inherits frmMain" in the class, as soon as I try
to build/run the program it gives me a System.stack overflow error. No
other indication of what's wrong.

Is this bad programming practice, or is there another way to refer to a
function in the main form?

Any help would be greatly appreciated.

Jun 7 '06 #8

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

Similar topics

8
2839
by: Bryan Parkoff | last post by:
I find an interesting issue that one base class has only one copy for each derived class. It looks like that one base class will be copied into three base classes while derived class from base...
14
2321
by: Jason Heyes | last post by:
I want to write a class that supports operations on keywords belonging to the C++ programming language. The following program repeatedly prompts the user for a keyword until 'explicit' is finally...
7
12952
by: A_StClaire_ | last post by:
hi, I'm working on a project spanning five .cpp files. each file was used to define a class. the first has my Main and an #include for each of the other files. problem is my third file...
5
14405
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
6
17548
by: Jon Hyland | last post by:
Ok, I'm a little rusty on this, it should be a simple problem but I can't figure it out. How can I handle form events in my main code page?? I'm creating a Windows App in C#. Rather than make...
7
2050
by: Boki | last post by:
Hi All, When we delacre a main, why we dlacre it inside form? Why not outside of form? If form contains main(), why not every form contains a main()... Best regards, Boki.
4
3124
by: Jim Langston | last post by:
This should illistrate what I am trying to do: template <class T> T SomeFunction( T parm ) { return parm; } template <class T> class SomeClass
10
2626
by: stonny | last post by:
I read the following sentence from a c++ website, but can not understand why. can anyone help me with it? " An important detail to keep in mind when debugging or implementing a program using a...
4
4367
by: dascandy | last post by:
Hi, For a project I'm working on I'm kind-of-hacking my way around deriving a class from an interface or such to create a mock, but instead creating the mock directly. It is usable as the...
0
6978
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...
0
7154
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,...
0
7190
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5451
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,...
1
4881
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...
0
4578
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...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.