|
|
this is what i whant to do
private void Form1_Load(object sender, EventArgs e)
{
Test(CLLER);
Test(Bob);
}
private void Test(?????? t)
{
//t should be the sub i want to call! so how would i do this?
t("Test");
}
private void CLLER(string T)
{
MessageBox.Show(T);
}
private void Bob(string T)
{
this.Text = T;
}
thanks
codegreen
-- modified at 19:52 Thursday 17th November, 2005
|
|
|
|
|
I think you have the wrong impression of method overloading. Why not just do
..In the form load event
{
Test(CLLER); <<-- Assuming these are string objects
Test(Bob); <<-- Assuming these are string objects
}
void Test(string T)
{
if(String.Compare(T,"CLLER")== 0)
{
MessageBox.Show(T);
}
else
{
this.Text = T;
}
|
|
|
|
|
because i have a more complex code
public void CheckCrossThread(string data, string scase)
{
//DataReceived(this, data);
if (((System.Windows.Forms.Form)_Form).InvokeRequired)
{
SetTextCallback d = new SetTextCallback(CheckCrossThread);
((System.Windows.Forms.Form)_Form).Invoke(d, new Object[] { data,scase });
}
else
{
switch (scase)
{
case "DataReceived":
DataReceived(this, data);
break;
case "Disconnected":
Disconnected(this);
break;
case "TCPError":
TCPError(this, new Exception(data));
break;
default:
TCPError(this, new Exception("Not Found")); ;
break;
}
}
I use this for most of my projects but its hard to keep editing it over and over again. i would like (scase) to call the sub it was passed
thanks
codegreen
|
|
|
|
|
Take a look at the "delegate" keyword.
|
|
|
|
|
Instead of having to do a switch and determine which method to execute based on the string value, I'd recommend passing some delegate that contains the code to execute. For example, using C# 2, if I wanted CheckCrossThread to execute DataReceived method, I could do:
this.CheckCrossThread("someData", "DataReceived", (System.Threading.ThreadStart)delegate{ DataReceived(this, "someData") });
public void CheckCrossThread(string data, string scase, ThreadStart methodToExecute)
{
...
methodToExecute();
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Bought a House!
Judah Himango
|
|
|
|
|
that is what i need thanks, BUT C# doesn't like
this.CheckCrossThread("someData", "DataReceived", (System.Threading.ThreadStart)delegate{ DataReceived(this, "someData") });
it says } needs ;
I fix that but it needs a method the DataReceived is and event
-- modified at 18:01 Friday 18th November, 2005
|
|
|
|
|
It can be done using reflection, but it is probably a little slow, so use it sparingly:
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
Test("CLLER");<br />
Test("Bob");<br />
}<br />
private void Test(string t)<br />
{<br />
GetType().InvokeMember(t, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.InvokeMethod, null, this, new object[] {"Test"});<br />
}<br />
private void CLLER(string T)<br />
{<br />
MessageBox.Show(T);<br />
}<br />
private void Bob(string T)<br />
{<br />
this.Text = T;<br />
}<br />
}<br />
Check out the documentation for InvokeMember, for more information.
-----
In the land of the blind, the one eyed man is king.
|
|
|
|
|
I have code to call a DLL that I wrote in C (see end of message). This code has worked fine for months. I reloaded my OS and installed a fresh vs2005 rc and now I'm getting a System.DllNotFoundException. It also says: Unable to load DLL 'copy.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
My DLL is in my working directory just as it was before. My project setup has not changed and the working directory is specified correctly. What could have changed to cause this error?
[DllImport( "copy.dll", CharSet = CharSet.Unicode )]<br />
public static extern int BackupClose( long hash1, long hash2 );<br />
|
|
|
|
|
Hello everybody. I downloaded de VC# 8 Express. While it works well, I'm having a problem with the doc compiler. I do my comment stuff:
<br />
interface IProperty<br />
{ ... }<br />
And when I compile it, it generates me the XML output file. So far so good. However, I cannot find a tool that actually builds the documentation as in VC# 7. So my question is: is there available any tool that allows me to document C# 2 code (and I mean, human-readable documentation), or is there any integrated tool with VC# 8 Express?
Thanks a lot.
...it's not right in one life, too much rain...
|
|
|
|
|
I need to query ADAM from .net code. Could someone please point me in the right direction?
Thanks
|
|
|
|
|
And which reference to "ADAM" would you be referring to?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I was referring to 'Active Directory Application Mode'
|
|
|
|
|
Try searching MSDN for "C# ADAM". You'll find a bunch of examples.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
this code gives the error "A local variable named 'var' cannot be declared in this scope because it would give a different meaning to 'var', which is already used in a 'parent or current' scope to denote something else".
I don't see why it should be a problem, the 1st i is out of scope before the 2nd one is created.
<br />
int[] intarray = new int[10];<br />
foreach (int i in intarray)<br />
{<br />
i++;<br />
}<br />
int i = 5;
|
|
|
|
|
The first 'i' is not out of scope of the second i. When a variable is declared in a foreach/for loop it is the same as the following.
int i;
for ( i=0; i++; i<5 )
{
}
The scope of the variable is outside of the loop.
|
|
|
|
|
You're not allowed to do this:
int i = 5;
if (x==0)
{
int i = 7;
}
because the second one 'hides' the first. The compiler isn't smart enough to let you define a second i after the one in a loop, it just works out that you have one in an inner scope, and one in an outer scope. If you put the int i = 5; inside another scope, so that there was no chance of it to flow down, then the compiler would be fine.
Something like this
int i = 0;
for(;i
|
|
|
|
|
P.S. why is this site so hard to use ? I've tried to post this three times and got three different error messages.
Yeah, the server is down quite often lately. Either it's a "Service unavailable", "500 error" or I can't even connect to codeproject.com at all
modified 12-Sep-18 21:01pm.
|
|
|
|
|
The load balancing portion of CodeProject isn't working properly at the moment. Chris is working on the issue...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
CG, use secure.codeproject.com for now. Much more performant and zero timeout errors.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Bought a House!
Judah Himango
|
|
|
|
|
Cool - thanks for the tip. I was expecting you to have explained why my answer was wrong :P
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
This is great!
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hello,
I want to launch numerous Window Applications from a MAIN window which will contain the list of all posible functions the user can perform. Similar to Microsoft Solomon layout. Solomon has the main window with list of functions, and the user can launch any of them, and interact with the windows separetly. I think threading is the way to go here, and how can I achieve that using threading?
Thank you.
|
|
|
|
|
Why don't you just create new child forms? They will be fully functional just as if they were seperate applications. If you just use Show(), they will be modeless so all are running at once.
|
|
|
|
|
Hi All,
I want to display different icon overlays for files and folders
depending on their state.I know how to add icon overlay but my problem
is how i can add more than one icon overlays .I have searched in
groups including this one also but the point was not clear to me. if i
want to add different icon overlays like tortoise svn then whether i
have to implement different icon overlay handlers (seperate dlls) or it
can be done by one executable itself.I have looked in the registry and
toroise svn uses 7 different guid for 7 different icon overlays but on
having a look on there code
http://www.koders.com/cpp/fid177A0F35D08F35B05D2783D4504BF24B4CE88EF2...
does not suggest using different executables as i use C# so i did not
get how they are doing it.atleast they are not using seperate dlls.any
suggestion is most welcome.Thanks.
Rakesh
|
|
|
|