|
it worked!
thanks a lot, you really helped me!
sam kline
|
|
|
|
|
I would like to provide an alternate point of view, if you don't mind. You don't have to call the method from messagefom . The ShowDialog method blocks the main thread until it returns. If you need to call the same function every time, then you could do something like this:
namespace.sendmessageform messageform = new namespace.sendmessageform();
messageform.ShowDialog();
this.callTheFunctionYouNeedToCall(); If you have more than one function that can get called, you could define a property in your sedmessageform that your main form can access to decide what to do next. For example,
namespace.sendmessageform messageform = new namespace.sendmessageform();
messageform.ShowDialog();
switch( messageform.SomeProperty )
{
case SomeEnum.Case1:
break;
case SomeEnum.Case2:
break;
} This design is more loosely coupled and does not require that your sendmessageform know about your main form. That would allow for better code re-use if you would like to use your sendmessageform again in another application or in another place in the same application.
I hope that helps you in some way.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
i never knew that it blocked the main thread, it will definately help me some time. thanks for the tip.
sam kline
|
|
|
|
|
I have a question.
I have an assembly built in debug mode that I want to explore.
I wish to explore this assembly through Reflection, and at the break points, suspend execution and have a look around.
This can be done in VS.net, which is obviously well plugged into the CLR, but this has to also be possible outside the enviroment. Can this be done on code called by Reflection? Now i'm guessing that the whole breakpoint system is already built on reflection, so how is this done?
Cheers
Cata
|
|
|
|
|
|
Hello,
I'm having a problem with events, I did some tutorials and I guess I understand how to use them, but I can't get this piece of code to work...
I get a NullPointReference Exception :
......<br />
<br />
<br />
public delegate void MovementEventHandler();<br />
<br />
public class Beagle<br />
{<br />
private int x;<br />
private int y;<br />
public bool uptodate;<br />
<br />
public event MovementEventHandler Movement;<br />
<br />
public Beagle()<br />
{<br />
new Beagle(0,0);<br />
}<br />
<br />
public Beagle(int x, int y){<br />
<br />
<br />
this.x = x;<br />
this.y = y;<br />
<br />
Movement();<br />
}<br />
....<br />
}
Tnx in advance !
-- modified at 11:49 Thursday 24th November, 2005
|
|
|
|
|
sciamachy wrote:
public Beagle()
{
new Beagle(0,0);
}
Hmm, this allocates a new instance of the Beagle class without assigning it to anything. Unless this is a construct new to C# v2.0 that I'm not aware of, I don't think you're accomplishing anything. Someone help me out here, if I'm wrong.
To initialize your fields, you can do this:
public Beagle()
{
this.x = 0;
this.y = 0;
this.uptodate = true;
}
sciamachy wrote: // Update world
Movement();
Oops! You're raising the event without checking to see if it is null. If no one has yet subscribed to the event when you attempt to raise it, you'll get a null exception.
Better to do something like this:
protected virtual void OnMovement()
{
MovementEventHandler handler = Movement;
if(handler != null)
{
handler();
}
}
And call this method from elsewhere in your class when you need to raise the event.
|
|
|
|
|
Hello,
Is there a way of passing a dataset, or something like that, to populate a treeview, and not add a node at a time. And how to indicate in the dataset, or array the node hierarchy?
Thank you.
|
|
|
|
|
Searching CodeProject sometimes gives valuable hits[^]
|
|
|
|
|
Hi all,
As I was reading C# Language Pocket Reference, it says that all parameters are passed by value(ASAIK the book targets .NET 1.0). I thought that all reference types were passed by reference and all value types by value(enums and ints/floats/etc)? Is that the case?
Thanks,
gamehack
|
|
|
|
|
1nsp1r3d wrote: As I was reading C# Language Pocket Reference, it says that all parameters are passed by value(ASAIK the book targets .NET 1.0).
Correct, unless the ref modifier is used.
1nsp1r3d wrote: I thought that all reference types were passed by reference and all value types by value(enums and ints/floats/etc)? Is that the case?
Nope.
When a reference variable is passed to a method, it is by default passed by value. So if you were to do something like this:
public void SomeMethod(string name)
{
name = "B";
}
Only the local name variable is changed. The reference variable passed to the method is not changed:
string name = "A";
SomeMethod(name);
So when a reference variable is passed to a method, it is passed by value by default. A copy of the variable is what is actually passed to the method. This local copy references the same object in memory as the original variable, but they are two distinct variables. Changes on the local variable itself does not change the original.
However, if you use the ref modifier, you have a reference to a reference, so to speak. So given our above example:
public void SomeMethod(ref string name)
{
name = "B";
}
string name = "A";
SomeMethod(ref name);
Changes to the variable itself are reflected in the original.
|
|
|
|
|
string is a bad example, because it is immutable, so when you cannot actually change it. Each time you are creating a new string object.
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
1nsp1r3d wrote: I thought that all reference types were passed by reference and all value types by value(enums and ints/floats/etc)? Is that the case?
Yes, you are correct.
Consider this small application:
using System;
namespace ConsoleApplication12
{
class A
{
private string someValue;
public string SomeValue
{
get
{
return this.someValue;
}
set
{
this.someValue = value;
}
}
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("In the Main method");
A mainA = new A();
mainA.SomeValue = "This was set in the main method";
Console.WriteLine(mainA.SomeValue);
AnotherMethod(mainA);
Console.WriteLine(mainA.SomeValue);
Console.ReadLine();
}
static void AnotherMethod(A parameterA)
{
Console.WriteLine("In AnotherMethod");
Console.WriteLine(parameterA.SomeValue);
parameterA.SomeValue = "This value was set in AnotherMethod";
Console.WriteLine(parameterA.SomeValue);
Console.WriteLine("Exiting AnotherMethod");
}
}
}
The output would be:
In the Main method
This was set in the main method
In AnotherMethod
This was set in the main method
This value was set in AnotherMethod
Exiting AnotherMethod
This value was set in AnotherMethod
As you can see, the object of class A is passed by reference because when its property is updated in the method, the update is reflected in the Main method after the call.
Does this help?
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
Colin Angus Mackay wrote: As you can see, the object of class A is passed by reference because when its property is updated in the method, the update is reflected in the Main method after the call.
I'm sorry, but this isn't corrent. The variable mainA is passed by value to AnotherMethod . The parameterA is another variable that references the same object in memory as mainA .
Changing the property value in AnotherMethod changes the object that is being referenced by both mainA and parameterA . That is why the change is reflected outside of AnotherMethod .
Operations on parameterA itself are not reflected outside of that method:
static void AnotherMethod(A parameterA)
{
Console.WriteLine("In AnotherMethod");
Console.WriteLine(parameterA.SomeValue);
parameterA = new A();
parameterA.SomeValue = "This value was set in AnotherMethod";
Console.WriteLine(parameterA.SomeValue);
Console.WriteLine("Exiting AnotherMethod");
}
If you were to pass mainA by reference, changes to parameterA itself would also change mainA .
static void AnotherMethod(ref A parameterA)
{
Console.WriteLine("In AnotherMethod");
Console.WriteLine(parameterA.SomeValue);
parameterA = new A();
parameterA.SomeValue = "This value was set in AnotherMethod";
Console.WriteLine(parameterA.SomeValue);
Console.WriteLine("Exiting AnotherMethod");
}
|
|
|
|
|
Ah... Yes, I see what you mean. You are correct. I guess I made part of the mistake I was trying to show not to make.
What I was trying to say was that you create an object in one method and pass it to another method. The other method can update the object and the changes would be reflected in the calling method. Of course, I failed to mention that if you assign a new instance of class A to the parameter value then it wouldn't be reflected because that would be local to the method.
Anyway, everything's sorted out now.... I hope....
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
Colin Angus Mackay wrote: Anyway, everything's sorted out now.... I hope....
It's kinda tricky to wrap your head around. I started out with C years ago where things were on a much lower level than in C#. So you would deal with pointers directly instead of the higher level references C# gives you.
I can remember years ago doing something like this (in C):
void SomeMethod(int *pointer)
{
pointer = malloc(42);
}
And calling this function elsewhere:
int *p;
SomeMethod(p);
p[0] = 0;
And wondering why memory wasn't being assigned to the variable passed into SomeMethod .
I posted to comp.lang.c, not for the faint of heart, and was told rather sternly that the reason the variable being passed to the function wasn't being updated is that it was being passed by value. Think of the pointer has having a value, and that value is the address of the memory it points to. This value is what is passed to the function and is stored in the parameter variable. If I change the parameter variable itself, such as assigning memory to it, it's not reflected outside of the function.
That's when I learned about the wonderful "pointers to pointers." So what I needed to do (and my C is really rusty, so pardon me if this isn't exactly correct), is:
void SomeMethod(int **pointer)
{
*pointer = malloc(42);
}
And calling this function elsewhere:
int *p;
SomeMethod(&p);
p[0] = 0;
Now, I'm not sure how things are under the covers in C#, so only take my C example as an analogy of how things might work in C#. But the concepts are the same.
The reference variables reference, or point, to an object somewhere. When a reference variable is passed to a method, its value is passed to the method and stored in the parameter variable. So the parameter variable references the same object; it has the same value. Operations, such as setting properties, calling methods, etc., performed on on the parameter variable local to the method are performed on the same object referenced by the variable passed to the method.
Pointers to pointers are the equivalent of using the ref modifier in C#. ref gives you a reference to a reference so that operations performed on the parameter variable are reflected outside of the method. Think of a ref variable as a reference to the variable itself that was passed to the method.
Well, hopefully some of that makes sense.
|
|
|
|
|
Leslie Sanford wrote: and my C is really rusty, so pardon me if this isn't exactly correct
I haven't done C++ in about 5 years now. I understand what you mean though.
Leslie Sanford wrote: Well, hopefully some of that makes sense.
Absolutely.
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
Okay - I guess I made some mistakes with my explanation.
1nsp1r3d wrote: I thought that all reference types were passed by reference and all value types by value(enums and ints/floats/etc)?
A reference type is passed by reference insofaras you can update the object in the method and the changes will be reflected back in the original, but you cannot assign a new object.
If you use ref you are passing a reference to a reference and you can assign a new object in the method and have that new object reflected in the calling method.
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
-- modified at 11:03 Thursday 24th November, 2005
|
|
|
|
|
I discovered a great feature of new VS 2005 - to allow use of Classes as datasources for reports.
I created a simple class with a couple of public string fields that source my report and they show quite happily in report viewer. Great functionality.
Now, I am trying to see if I can source an Array-like type to report and get it to show the data. For example say I have a Book class, that will conain name of the Author, number of pages, price and a HashTable (or another suitable) of characteristics: size, page colors and index.
Something like:
public HashTable OtherVals
{
get{
HashTable my = new HashTable();
my.Add("size","10x15");
my.Add("PageColor", "green");
return my;
}
}
How can this be shown on report?
Rewording of this quetsion below...
the .rdls report templates, when a Class is used as its datasource - what sort of data types can it handle?
In other words - strings work great, ints etc... How about ArrayList() or HashTable() or something that will allow me pass a list of 5 items into the report and show them in a list.
Thanks a lot!
Alexander Bolotnov
|
|
|
|
|
Hi,
I am converting a decimal value to string for displaying it on a label.
While converting the decimal value with two decimal places to string, 4 more zeroes are being appended to the decimal value.
eg: "45.52" is displaying as "45.520000" on label after using the following statement:
decimal d = 45.52
lblNetPrice.Text = Convert.ToString(d);
What I need to do for displaying 2 decimal values on the label other than using the substring function?
Thanks in advance.
Subrahmanyam K
|
|
|
|
|
lblNetPrice.Text = String.Format("{0:#.##}",d);
/edit: helps if you get the format right
-- modified at 8:05 Thursday 24th November, 2005
|
|
|
|
|
Instead of this:-
Subrahmanyam K wrote: decimal d = 45.52
lblNetPrice.Text = Convert.ToString(d);
try this:-
decimal d = 45.52
lblNetPrice.Text = d.ToString("###,##0.00")
Cheers,
Craig
** I'd rather try and fail than fail to try **
|
|
|
|
|
hello all,
i am working with windows control library . i am using three dll in my project. which ever dll i am using i have to make strong name for that.my problem is that i am not to able make strong name more than one. in Assemblyinfo.cs i used the following coding
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile(@"..\..\..\filename.snk")]
[assembly: AssemblyKeyName("")]
after that use GAC to put into the assembly. for each dll i have to make .snk key pair. but when i use AssemblyKeyFile() more than once in assembleinfo.cs it gives me error duplicate assembleykeyfile() file attribute. how could i use more than one dll in our project.
Amit Grover
CDAC R&D
Gist Group
pune
|
|
|
|
|
The AssemblyKeyFile attribute is used to *build* a strong named assembly, you don't need it for referring to a strong named assembly.
So you need to have the attribute in the AssemblyInfo.cs file of each of the DLL projects, that's it.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
i don'nt know how would to add entries in assembleInfo.cs for each of the dll's. plz send the code if possible
Amit Grover
CDAC R&D
Gist Group
pune
|
|
|
|