|
N a v a n e e t h wrote: only required when the call accesses control's handle
I don't know. If all the property does is return the value of a class member, then that would make sense. However, AFAIK the documentation doesn't say which control properties do or don't access Handle? So should I gamble on this?
[ADDED]A little experiment confirms a thread can get a button's text without a cross-thread exception being thrown, but not a combobox text. [/ADDED]
If the rule were "reading a property is always fine, independent of handles", that would be nice. But it isn't.
Any references that shed a light?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
modified on Monday, October 26, 2009 7:51 AM
|
|
|
|
|
Luc Pattyn wrote: [ADDED]A little experiment confirms a thread can get a button's text without a cross-thread exception being thrown, but not a combobox text. [/ADDED]
That was my point. ComboBox.Text is using the handle. Watch the stack trace and you will see error thrown at the point where it touches handle.
But after investigating further, I too think that its kind of gambling. As you said using Invoke/BeginInvoke would be safe as the documentation doesn't say anything about how the properties are implemented.
Best wishes,
Navaneeth
|
|
|
|
|
I now have extended my article[^] accordingly.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I have a MDI project with a few child forms, and each child form is performing a function, some of which are dependant on nother.
It is a CAN bus reader, so I have a form which sets up and configures the hardware (connected by USB), another one to read the data and put it in a table, another form which can graph some of the data packets in a plot, etc...
My question is in the example above, most of the forms need access to the HW defined in the setup form.
I find myself unable to get data from the table in form 1 to the plot in form 2.
I am new at this, but I got it all working in a single form with tabs, and decided that I would like to have the look and feel of MDI so I can see multiple windowns together, and hit this road block. I thought it would be as simple as calling this for example from FormData --> if(FormSetup.CheckBox == True), but it seems I cannot access an object in another form to check its status or its text, etc...
And the same does not work if I am trying to cal a function.
Is there a place in C# Express I can declare all my valiables and functions so they can be accessed by everyone from the Parent to the Child form? All my objects are set to Internal, and so are my functions. I am just stuck on probably a simple details.
Any help or pointer?
Thanks,
H-
|
|
|
|
|
If any child contains data that may be needed by another sibling, it should send that data when it changes via an event to the parent. The parent should hold a reference to each child (in a MDI WinForms app it already has a MdiChildren property) and on handling these events, notify any others that need to know via a method call or property set.
This will keep all your forms properly separated as they do not need to know about each other directly and be a much cleaner design.
Dave
"My code works, but I don't understand why!" - DaveyM69 (Me) BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
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);
|
|
|
|