|
Thank you very much!
Still learning...
|
|
|
|
|
Hi,
I have the following:
namespace Server.Layer1
{
public class BaseClass : MarshallByRefObject
{
public enum SomeEnum
{
Zero = 0,
One = 1
}
abstract public IMyInterface CreateImplmentor(SomeEnum anEnum);
}
}
Here is IMyInterface
namespace Server.Layer2
{
public interface IMyInterface
{
bool Save(Student aStudent);
event AnEventHandler SomethingHappened;
}
public delegate void SomethingHappened(object sender, EventInfo e);
}
I have registered the class which implements the BaseClass functionality and register it using a
console application host. Compiles fine.
I have a client but when it connects to BaseClass, exception is thrown at this line:
BaseClass classReceived = (BaseClass ) RemotingServices.Connect(typeof(BaseClass),
"http://localhost:65100/RemoteClass");
Exception is: "Trying to create a proxy to an unbound type."
Student is Serializable. BaseClass is MarshalByRefObject and so is the class which implements the IMyInterface. I am not sure what the problem could be. If a class inherits from MarshalByRefObject and has delegates or events, do they need any special attributes?
Please help,
Thanks
|
|
|
|
|
Hi,
I have an issue where I get a pointer to unmanaged data (along with the number of bytes allocated) from a device and I need to perform a checksum on this data. While I have found plenty of information to pin a managed array and feed that to a C library call, I have been unable to find any methods for going to other way around.
public static byte[] MD5Checksum(unsigned char* data, int dataLength){<br />
<br />
byte[] unmanagedWrapper = MagicalMethodToWrapUnmanagedArray(data, dataLength);<br />
<br />
return System.Security.Cryptography.MD5.Create().ComputeHash(unmanagedWrapper);<br />
}
Thanks in advance!
B
|
|
|
|
|
|
On a windows for, after clicking a button, I add a class Student to an ArrayList with
ArrayList Grade10 = new ArrayList();
Grade10.Add(new Student(a, b, c, d, e); //Student declared as public class elsewhere
This seem to work fine.
However, I then want to load the items in a Listbox when another button is clicked. I use
foreach (Student i in Grade10)
lbxShow.Items.Add(" " + i);
I get message that Grade10 does not exist in this context. If I declare Grade10 again in this event it appears that the ArrayList is empty - program runs, no errors, empty ListBox.
All samples I find refer to console apps. These work for me but I cannot sort out the windows form - my first attempt at C#, I've been using Delphi for ages.
Seems I have to declare ArrayList Grade10 somewhere else (global?) so it is visible inside the second button event as well?
Much appreciate someone showing me the way.
Hannes
|
|
|
|
|
Hi,
it has nothing to do with console app vs windows app.
the problem is Grade10 is "not in scope" where you try to use it, otherwise
"declaring Grade10 again" would result in a compile-time error.
Anyway, declaring again, or performing one more new, never solves anything, since then
you are stuck with an object that is different from the original, so does not hold its
content, etc.
If you want detailed help, publish the actual code, not pieces of it.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Yep sounds like a scope issue. Not sure where you actually have declared Grade10 and where you've tried to use it but thats a safe bet as to what your problem is, but I can't help you without more code.
Sidenote: Use List instead of ArrayList, they're better for you
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
Mny thkx so far Here's the code I'm using:
class Student
{
string sName;
string sSurname;
string sID;
bool bGender;
double dAmount;
public Student(string sN, string sS, string sI, bool bG, double dA)
{
sName = sN;
sSurname = sS;
sID = sI;
bGender = bG;
dAmount = dA;
}
public override string ToString()
{
return
string.Format("Name: {0} Surname: {1} ID: {2} Male: {3} Account: {4}",
sName, sSurname, sID, bGender, dAmount);
}
}
private void button3_Click(object sender, EventArgs e) //Click Add button
{
bool g = false;
if (rbBoy.Checked)
g = true; //then it is a boy
//Now add this student to the ArrayList
ArrayList Grade10 = new ArrayList();
Grade10.Add(new Student(txtName.Text, txtSurname.Text, txtID.Text, g,
Convert.ToDouble(txtAmount.Text)));
}
private void button2_Click(object sender, EventArgs e) //Click Show button
{
// ArrayList Grade10 = new ArrayList(); //I'm sure this is cannot be!
foreach (Student i in Grade10)
lbxShow.Items.Add(" " + i);
}
Hannes
|
|
|
|
|
Hi,
variables are local to the first {} block that contains their definition, and can not
be touched by anything outside this same {} block.
how could button2 reach the Grade10 ArrayList that you have defined inside button3_Click???
furthermore, the data structures are all wrong: what would happen if you never click
button3 but do click button2. Where would it get its information?
you clearly need to buy and study a tutorial on C# and pay attention to local variables,
class members, etc. And rethink your program structure.
If button3 is intended to add a student to the collection, with information from input boxes,
then:
- why don't you keep the new student collection alive at the class level?
- why don't you add the new student to the lbxShow immediately? (and forget about button2)?
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Thkx for the suggestions, I am indeed wading my way thru a recently purchased 1500-page C# book - while trying to keep up with teaching, examining and marking 200 kids learning Delphi. We have been teaching Delphi at school for some time now (some schools teach Java) and forsee it making way for C#. Questions asked in exams are set so you can answer them in either Delphi or Java. I have set a typical problem - a button to add an object to an ArrayList (Delphi would use a dynamic array, I don't know how Java would handle it), and a button to display the array. Typically, a question would also have buttons to sort and to locate/delete/insert an object. The form design will be given, sometimes even the data. Learners must then make the buttons work.
I know global variables defeat the aims of OOP, but I was trying to define the ArrayList as such. So, to some extent, it's not about elegant solutions at this level but rather just getting to grips with the basics.
Hannes
|
|
|
|
|
I am using the ListView.SelectedIndexChanged to update data, when a new item has been selected.
My problem is, that the event will be fired for each new selected (de-selected) item (if multiSelect is true; more than twice). [And i don't want to get the data from the database each time.]
Is there an event that will be raised if the control has finished handling these processes (or processes for this control at all)?
Or does anyone have another idea to solve thsi problem
|
|
|
|
|
C-Scharbe wrote: Is there an event that will be raised if the control has finished ...
No.
The Control can not guess when you have finished selecting and de-selecting, so the only
thing it can do is fire every time. Either apply code that can stand this, or add some
way for the user to confirm the selection process is done, e.g. a button.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
It's too complicate...
... for the user to click an extra button
I missing something like LastSelectedIndexChanged or AfterSelectedIndexChanged.
|
|
|
|
|
It's too complicate...
... for the computer to read the user's mind
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Perhaps he could use classes from the DWIM namespace...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Unfortunately a lot of methods in System.DWIM throw a NotImplementedException.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
So there is minimum a
throw new Exception("The method or operation is not implemented.");
implemented !!
|
|
|
|
|
What is DWIM?
Tell me more
Or send me a link....
|
|
|
|
|
Here's[^] the documentation for the namespace...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Does anyone have an idea, to solve this problem??
|
|
|
|
|
Hello
I'm trying to bind a list to a combobow but without effective result
class Rue<br />
{<br />
public int Id;<br />
public string Nom;<br />
};<br />
<br />
List<Rue> Rues = new List<Rue>();
Then I'm trying to fill and bind that list to a Combo
<br />
Rues.Clear();<br />
readRues("1000",Rues);<br />
cmb_rues.DataSource = Rues;<br />
cmb_rues.DisplayMember = Rues[0].Nom;
The Combo displays things but not what I expect
It shows
App.Form+Rue
App.Form+Rue
App.Form+Rue
etc..
Thanks for any help !
|
|
|
|
|
I think you need to write:
cmb_rues.DataSource = Rues;<br />
cmb_rues.DisplayMember = "Nom";<br />
cmb_rues.ValueMember = "Id";
|
|
|
|
|
Hello
I've try it too !!
Same result BUT
If I declare the ValueMember I got a message cannot bind to the new displaymember
|
|
|
|
|
Try this:
class Rue<br />
{<br />
public int Id;<br />
public string Nom;<br />
<br />
public override string ToString()<br />
{<br />
return Nom;<br />
}<br />
};
|
|
|
|
|
Thank you
It works indeed !
But I really do not understand why and how ?
I'm old to C but new to csharp and oop
|
|
|
|