|
Well, generally, how can an object call a mrthod of an other object? Well, the calling object must have a reference to the other object and with this reference it can call any public method of the referenced object. Your two forms are objects, so this will work for them too.
C# does not have anything like global variables for a good reason. There are some things which come close, like static methods and variables, but these things should be used with some caution. Using them carelessly can easily result in a program which is buggy, hard to correct and maintain and generally a pain to work on. I understand that a beginner tries to focus on getting the job done, but when you have been in code hell a few times you will see that that reaching the goal is not all.
As a rule of thumb: If you have to tweak your code, there always is something wrong with your design. Object oriented design in this case. Now let's see...
This is the simplest but certainly not the best way to do it: Let's say there is form A which must be notified when a certain thing happens to form B. When form B is opened it receives a reference to it's partner, form A. Whenever something happens to form B which form A must get to know about, form B can use this reference to call methods of form A.
Edit: I just saw the reply before mine. Notifying the parent with an event which in turn decides which children are to be notified is indeed a much cleaner design. It also probably will involve a little more reading articles and learning.
modified on Sunday, October 25, 2009 3:50 PM
|
|
|
|
|
Thanks for the replies. I will read up on the method of going through the parent. This way, the parent can have all the "global" parameters which I need.
So in non-good-SW-design language, I can pass all parameters (whatever they are from text to check box, etc...) to the parent, and the parent can keep them and pass them to the next child.
Do I get it right?
I will have to read up on how to do it now. Thanks for the direction.
H-
|
|
|
|
|
On thing I failed to ask:
- Is there a good article on codeproject.com which goes through this? Or would you recommend a beginner's book which can help get started on C# the right way?
Thanks,
H-
|
|
|
|
|
|
I am in the final year of my studing
and I must make Project and I do'nt have any new idea for making the project
please help me to make not defficult and easy project 50:50
my email: action57392@hotmail.com
Thanks
|
|
|
|
|
Abdaqader wrote: and I must make Project and I do'nt have any new idea for making the project
Take a look here[^], where you will find hundreds of articles with excellent ideas and suggestions.
|
|
|
|
|
It is very hard to help u that way. Better you should read basic books to grow your knowledgebase and then try yourself...
After that if you still find problems, ask specific problems. We would glad to help you that time.
By this way, you will also learn basics of .NET.
|
|
|
|
|
This is asked often and it's a dumb question. You know best what your areas of strength are ( although you seem to me to be saying that you don't have any ? ), and what is likely to impress your teachers.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I think you should write a program to analyse all pieces of music that have ever been recorded, and identify common themes, motifs and rhythmic structures used therein. In order to do this, you should load the music into the memory of all the machines that you use and perform the analysis there without letting the program stop at all. Let the program run for as long as possible, and hopefully the fact that your machine is locked up will stop you posting lame questions like this.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Actually, this has already been done ... and is being used to predict which new "tunes" will be a hit / popular based on their structure relative to other popular tunes.
|
|
|
|
|
Yeah but if this guy attempts it he will surely disappear for some time, which is Petes goal.
|
|
|
|
|
I am in the final year of my studing
and I must make Project and I do'nt have any new idea for making the project
please help me to make not defficult and easy project 50:50
my email: action57392@hotmail.com
Thanks
|
|
|
|
|
Noone can help you. You have to come up with a project idea that suits your skill level and is of interest to you.
Noone is going to do this project with you "50:50". This is YOU work assignment for YOUR class to demonstrate that YOU have learn the skills necessary to pass it.
|
|
|
|
|
Harsh, but true. In college I also had to do such an assignment together with three young ladies who unfortunately did not even know where to begin. In the end I wound up doing practically everything myself. I even managed to coach them through the discussion of the rsults with the professor, who obviously knew what was going on and simply played along. So we all got a passing grade, but I was the only one who also learned a little.
|
|
|
|
|
PreProc wrote: but I was the only one who also learned a little.
That is why we always advice people to at least try themselves....
|
|
|
|
|
He means he wants the project idea to be 50% easy and 50% challenging.
I agree, this is a dumb question and I don't get why so many people ask it.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
hi. Dunno how to properly name the question, but here it goes.
I got my lib (dll) exporting function which returns 2 unsigned long values:
1 is a single number and
2 is table which contains a lot of numbers. Basically it looks like this:
DWORD MyFunc(PULONG table, PULONG nr);
then call it:
ulong table[256];
ulong nr;
MyFunc(&table, &nr);
My dll is written in win32 api. Next i got C# app which have to access to this function.
And here i dont know to do it. Any suggestions?
code like:
Uint32[] table= new Uint32[256];
Uint32 nr = new Uint32();
MyFunc(out table, out nr);
crashes C# app.
|
|
|
|
|
csrss wrote: crashes C# app.
You cannot call a C/C++ Win32 function directly from C# in this way. You need to use the P/Invoke[^] mechanism.
|
|
|
|
|
Yes, i am using pinvke, i am loading my dll like this:
[DllImport("C:\\Users\\Administrator\\Desktop\\TinyDLL\\TinyDLL.dll", CharSet = CharSet.Auto)]
public static extern int function(
ref int[] table,
ref ulong nr
);
I am doing everything like it should be done. I know how to use win32 functions and pure native API functions from C# application. But i got no idea how this could be translated to C#:
ULONG something[256];
GetThisSomething(&something);
while "something" will contain tables of integers 
|
|
|
|
|
csrss wrote: ULONG something[256];
GetThisSomething(&something);
while "something" will contain tables of integers
I think you need something like:
int[] intArray = new int[256];
ulong ulNumber = 0;
GetThisSomething(ref intArray, ref ulNumber);
|
|
|
|
|
That is exactly what i am doing. And unfortunately it does not returning Table. It returns single number just fine but fails with Table 
|
|
|
|
|
Hi,
you can't use out or ref for this.
you need one of two techniques that ensure the arrays don't get moved around by the GC:
1.
The fixed keyword (C# only): it requires the unsafe keyword, and the "allow unsafe code" compiler switch; it fixes the object, and allows you to get its pointer. Here is a C# example:
unsafe public int ArrayFixed() {
int dim=1000;
int[] numbers=new int[dim];
...
int sum;
fixed (int* pNumbers=&numbers[0]) {
sum=SumArray(pNumbers, dim);
}
return sum;
}
[DllImport("native.dll")]
unsafe public static extern int SumArray(int* pNumbers, int count);
2.
The GCHandle class: it does not require any "unsafe" stuff; one needs to pin the object, get the pointer, and when done to unpin the object; here is a C# example:
public int ArrayHandle() {
int dim=10000;
int[] numbers=new int[dim];
...
GCHandle handle=GCHandle.Alloc(numbers, GCHandleType.Pinned);
int sum=SumArray(handle.AddrOfPinnedObject(), dim);
handle.Free();
return sum;
}
[DllImport("nativeC.dll")]
public static extern int SumArray(IntPtr pNumbers, int count);
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Luc Pattyn wrote: you need one of two techniques that ensure the arrays don't get moved around by the GC:
I should have remembered that from your article 
|
|
|
|
|
Right.
I'm still working on the subject; seems like it may grow into a series of 3 or more articles.
And it is getting more and more difficult to introduce all of it in a logical order as it all is strongly interconnected.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Luc, thanks very much, i will try this out
Edit: Now i got "unable to load dll, access to invalid memory location" ;/
This c# is killing me, i cannot even export simple HelloWorld function which return messagebox...
Going to switch back to gtk gui development, thanks anyway for your help guys.
modified on Sunday, October 25, 2009 9:04 PM
|
|
|
|