|
Could not the end-developper ideally control that using a compiler attribute?
my 2 cents
R/
|
|
|
|
|
It would be possible to allow the developer to control that behavior, but I think that allowing the user to change the language rules is a bad idea, as it complicates the language. Adding options often makes the user's lives harder, not easier.
|
|
|
|
|
I think it's a good idea. Those who don't like it can just not use it.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
I don't think so.
Isn't 0 valid for both enums, but 4 is invalid for the first?
Aren't the valid numbers for the Suit enum 0 - 3, while the valid numbers for the Rank enum 0 - 12 ?
That's why you shouldn't use "number" to access. Always use them in the true OO model, like Rank.JACK instead of a number.
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
You'll always need to explicitly cast an int value to an enum unless the int value is zero.
|
|
|
|
|
Any enum is based on an integer type, which has a defualt value of 0, thus Enum as a ValueType it needs also some kind of default state, thus 0.
<a TITLE="See my user info" href=http:
|
|
|
|
|
I have a form where i call a class with and start a subroutine
Class1 Class1 = Class1();
Class1.StartSub();
In my Mainform from where i call the class there is for example a label called "label1". Now i want to change the label1 from within the Class Subroutine ...
I tried following:
in the MainForm (Form1) set the label from private to public
and then in the Class:
Form1 Form1 = new Form1();
Form1.label1.text = "test";
It compiles without any error but it doesn't change the label.
Thanks for you help!
|
|
|
|
|
When you created the new Form1(), you created a whole new instantiation of that form in memory, so you changed HIS label and not the one that is visible.
You could tackle that a couple of ways.
You could put in the Class1's constructor an argument for a label like this
Class1(label FormsLabelIWantToChange)
{
FormsLabelIWantToChange = "test";
}
Another way to do it (I think) would be to make Form1's label member s public static, then as you are in the same namespace you could do something like this in your class:
Form1.label1.text = "test";
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
If the XML file has whitespaces then it crashes my app. What I am doing wrong??
I get this "An error occured while parsing EntityName. Line 8, position 14."
That position it has whitespaces. I am actually testing my app.
<br />
<br />
FileInfo fileInfo = new FileInfo(fileName);<br />
<br />
XmlNode xmlRootNode;<br />
XmlTextReader xmlReader = null;<br />
if (fileInfo.Exists)<br />
{<br />
using (Stream strm = fileInfo.OpenRead())<br />
{<br />
using (StreamReader sr = new StreamReader(strm))<br />
{<br />
<br />
xmlReader = new XmlTextReader(sr);<br />
xmlReader.WhitespaceHandling = WhitespaceHandling.None;<br />
try<br />
{<br />
XmlDocument myDocument = new XmlDocument();<br />
<br />
myDocument.Load(xmlReader);<br />
....<br />
}<br />
<br />
}<br />
}<br />
Even if I open the XML file in IE, it fails. I get this error. "Whitespace is not allowed at this location. Error processing resource 'file:///C:/abcd.xml'. Line 8, Position 14"
I want to avoid those nodes where whitespaces exist.
Thx
Don't and drive.
|
|
|
|
|
you xml file is not valid - you what a whitespace where it is not allowed, post up the xml so we can see it.
if IE won't load it then theres no way your c# will load it.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Philip Fitzsimons wrote:
you xml file is not valid - you what a whitespace where it is not allowed, post up the xml so we can see it.
I know it's invalid. But in my app if any user uses invalid XML file, then I want to ignore the nodes where whitespaces exist.
If that's is not possible then what's the use of "WhitespaceHandling"??
Currently I am catching the exception. But the exception won't give much information like the one in IE. ('Whitespace is not allowed at this location. Error processing resource 'file:///C:/abcd.xml'. Line 8, Position 14")
Is there any specific exception to catch this kinda of errors?
Don't and drive.
|
|
|
|
|
white space handling is for manaing tabs and newlines - not for handling errors in XML documents.
My frst reaction would be to say you can't do this.
However, try using an XmlReader, you might be able to do some kind of partial loading of the document.
In general however, if the Xml document is not valid then you can't load it - not even partially.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Philip Fitzsimons wrote:
white space handling is for manaing tabs and newlines - not for handling errors in XML documents.
As I mentioned earlier I am testing my app for different scenarios where it crash, say if at all any user uses a XML file which contains whitespaces then I want to catch them and report the error properly.
Philip Fitzsimons wrote:
In general however, if the Xml document is not valid then you can't load it - not even partially.
Thx Philip.
One more question.
Is the same rule applies to "&", "<" and ">"??
Do I need to convert them to "&am p;" "&l t;" and "&g t;" ? (ignore the spaces)
Don't and drive.
|
|
|
|
|
You don't sound too sure of what you are doing - i.e. are you trying to REPORT the error or FIX it?
if you just want to report the error then use the exception information or use and XmlReader.
If you want to fix the error then you are going to have to do a lot of work with no real chance of being sure if your "fix" will result in the correct document.
Personally I would just report the error.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Philip Fitzsimons wrote:
You don't sound too sure of what you are doing - i.e. are you trying to REPORT the error or FIX it?
Intially I thought of FIX the error but after few hiccups I gave up that idea and just REPORTing error.
Thx for clarifying my stupid newbie questions.
Don't and drive.
|
|
|
|
|
Hi, everyone:
I am using VS.NET 2003 to create a winForm application ( Same result in VS.NET 2002). The application accesses MS Access DB so that an user can edit the DB.
When I have Datagrid bounded to the tables, all the updates (Insert,Delete and Update) work perfect. However, I have one table that I have to bound it to TextBoxes and CheckBoxes. If I insert or delete a record, it updates the DB fine. When I change the text in the texboxes, or click on the checkboxes, The record is supposed to be modified. When I click on my save button, I use table.GetChanges(DataRowState.Modified) to retrieve the changes. Surprisely, there is no changes, even though I thought I have the right binding.
Apparently, when I change the textboxes or checkboxes, the datarow status did not change to Modified. I can not figure out what I missed here. Please help. Thanks in advance.
Dion
More info:
I have columns as Text, Number and Yes/No in the MS Access DB. Here are the simplified code to do the binding:
For Number:
Binding b1 = new Binding("Text", dsMain1, "LMMaster.LMMasterLMSimConfig.LessonTime");
b1.Parse+=new ConvertEventHandler(TextStringToInteger);
b1.Format+=new ConvertEventHandler(IntegerToTextString);
txtLessonTime.DataBindings.Add(b1);
For Text:
txtConfig.DataBindings.Add(new Binding("Text", dsMain1, "LMMaster.LMMasterLMSimConfig.Config"));
For CheckBox:
chkboxHelp.DataBindings.Add(new Binding("Checked", dsMain1, "LMMaster.LMMasterLMSimConfig.Help"));
|
|
|
|
|
Hi,
You should end edit for the row. To do so, you need to run
txtConfig.DataBindings["Text"].CurrencyManager.EndCurrentEdit()
(more or less this way-I wrote it from my memory not copied from VS ) )
when user changes text or when textBox loss focus.
h.
|
|
|
|
|
What's the better way to terminate the following thread?
1. Method:
...
public void WaitForClient()
{
while (true)
{
try
{
Socket s = listener.AcceptClient();
...
...
}
catch (Exception)
{
break;
}
}
}
...
static void Main(string[] args)
{
listener = new TcpListener(8002);
listener.Start();
...
thread = new Thread(new ThreadStart(WaitForClient));
thread.IsBackground = true;
thread.Start();
...
...
listener.Stop();
thread.Join();
...
}
2. Method:
...
public void WaitForClient()
{
while (true)
{
Socket s = listener.AcceptClient();
...
...
}
}
...
static void Main(string[] args)
{
listener = new TcpListener(8002);
listener.Start();
...
thread = new Thread(new ThreadStart(WaitForClient));
thread.IsBackground = true;
thread.Start();
...
...
thread.Abort();
listener.Stop();
...
}
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
I would suggest a third method.
Use a variable to flag the thread that it needs to stop working. Then in your thread (presumably in a loop) check for the flag at regular intervals and bail out cleanly.
This is probably better handled by an Event object, but I haven't used them in C# as of yet. In a simple scenario a flag variable should do.
|
|
|
|
|
We have a Windows Service written in C# that simply host some remote
components. The service does nothing itself. We have an ASP.NET application
that initialises the remoting in global.asax and has a single aspx page that
creates the remote component and calls its method, which returns a small
string. Thing is that the service process leaks memory. Now I've read most
of the articles/books on the wonders of the GC and I know that what I'm
seeing is not normal behavour. And here the catch: if I run the application
as a standard process, i.e. I replace the call to ServiceBase.Run with a
long Sleep statement - the application does not leak memory. The CLR memory
performance counters show very different traces of #bytes on heaps running
the same test. What could be causing this behaviour? Could anyone from
Microsoft check to see if remoting components from a Service has memory
issues. In the ASP.NET page I simply release the object by setting the
reference to null. My tests run for several hours with several hour of low
and high load but the service never reduces it memory. The process version
remains very flat. I'm not using any unmanaged resources or any thing that
consumes loads of memory just small string (100 characters or so).
|
|
|
|
|
how much is it leaking?
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Hi,
My problem : I have a dataset (it don't have to be a
dataset, but I have no other idea) with 2 tables. 1 table
consists of a combination of several criteria and a
result code, and a second table with the description of
the resultcode in the combinationtable.
Ex. Combinationtable
Codename Sort result
Persontitle Natural 1
Persontitle Natural 2
Persontitle Firm 3
Persontitle Firm 4
ex. description
Codename Result description
Persontitle 1 Miss
Persontitle 2 Mister
Persontitle 3 Small Company
Persontitle 4 Company
In my application I choose the selectioncriteria ex. a
Natural person.
With this criteria I want to do a query (or find) on the
dataset, witch give me two rows (the first and the second
in this example).
I see that I have resultcode 1 and 2 and I will look for
the desciption of these resultcodes and bind (Miss and
mister) in a combobox. (Dynamically I will fill up the
combobox - so if you choose a natural person you will
have only choices in the combobox for titles for persons.
If it was a company only titles for the company are
displayed in the combobox).
Maybe it is possible to bind a query on a dataset to a
combobox? or something else.
Is there somebody who have an idea who I can solve a
problem like this. I will fill the dataset when I start
the application and it must stay in memory.
Thanks,
ron
|
|
|
|
|
Not quite sure I understand the situtation. The result code is what I am hanging on. Don't have a clue what this really is unless it is the link field between the two tables.
I am going to take a shot in the dark. If you have two tables and you want a master/detail type relationship between two combos, you would simply take the results when changed from the master combo box and use it as the view's filter criteria for the second combobox and base the second combobox on the DefaultView of the the detail table.
For an example, let's say I have two tables in a DataSet:
MembershipTypeGroups
MemebershipTypeGroup_ID
Description
Data:
1,"Personal"
2,"Business"
3,"Non-Profit"
MembershipTypes
MembershipType_ID
MembershipTypeGroup_ID
Description
Fee
Data:
1,1, "Basic", "Free"
2,1, "Enhanced", "$10"
3,1, "Premium", "$50"
4,2, "Business Basic", "$25"
5,2, "Business Premium", "$100"
6,3, "Non-Profit Basic", "Free"
Now, I have two comboboxes on a form. The first is set to the MembershipTypeGroups which is used to selected group of a membership which is Personal, Business or Non-Profit. The second combobox is keyed on the MembershipTypes table and is filtered by the selection of the first combobox. You bind the second combobox to the DefaultView of the MembershipTypes table in the DataSet. This allows you to change the "Filter" on the default view (DefaultView.Filter="MembershipTypeGroup_ID="+selectedValueOfFirstComboBox.ToString()) to select only those that match the selected primary key of the first combobox.
Rocky Moore <><
|
|
|
|
|
Can anyone explain me the Thread.IsBackground property! When to use? Why use?
And what does MS mean with:
A thread is either a background thread or a foreground thread. Background threads are identical to foreground threads, except that background threads do not prevent a process from terminating. Once all foreground threads belonging to a process have terminated, the common language runtime ends the process by invoking Abort on any background threads that are still alive.
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
As long as a foreground tread is running your app is running. If you create a Windows app that launches a forground thread and you close the app window without stopping the extra foreground thread you app will still be running.
If you create a background thread instead then the background thread will be terminated automatically when you close the app window.
I hope this was clear.
|
|
|
|