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. 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
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.
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
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
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
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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.
|
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
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |