|
that the C# compiler does great diagnostics. (This is my first essay into C# enumerable classes so if I've missed something obvious be gentle with me.)
I've written a class like this.
public class FilterEnumerator : IEnumerator
{
#region IEnumerator Members
private int index = -1;
private ArrayList data;
public FilterEnumerator(ArrayList Data)
{
foreach (String s in Data)
data.Add(s);
Reset();
}
public void Reset()
{
index = -1;
}
public object Current
{
get
{
if (index >= 0 && index < data.Count)
return data[index];
else
return null;
}
}
public bool MoveNext()
{
return (++index < data.Count);
}
#endregion
}
It compiles but the compiler throws a warning at me for the
private ArrayList data;
member pointing out that this member variable is never assigned to and will always be null . It took a bit of headscratching until I realised that the compiler was noticing that I had never actually created something for data to refer to. What confused me (does this show I'm a c++ programmer learning a new language ?) was that I could quite clearly see that I had assigned to data in the constructor. Or so I thought.
The solution is of course to write the constructor thusly:
public FilterEnumerator(ArrayList Data)
{
data = new ArrayList;
foreach (String s in Data)
data.Add(s);
Reset();
}
Well I say the solution is 'of course' but I'm still thinking in c++ terms. Is there a better solution?
And why am I convinced that the c# compiler does better diagnostics? I'm a firm believer in compiling at the maximum error level and converting warnings to errors. I want to know if the compiler thinks my code is questionable before I even start to debug it. But this error would have slipped past the c++ compiler.
Rob Manderson
Paul Watson wrote:What sense would you most dislike loosing?
Ian Darling replied.
Telepathy
Then I'd no longer be able to find out everyones dirty little secrets The Lounge, December 4 2003
|
|
|
|
|
Rob Manderson wrote:
Is there a better solution?
With .NET 1.x, why not use a specialized collection : System.Collections.Specialized.StringCollection. It lets you clone an entire collection with one method call.
Rob Manderson wrote:
And why am I convinced that the c# compiler does better diagnostics?
Yeah, better infrastructure, I think it shows pretty well.
That said, practically 100% of interop issues will pass through the compiler without being seen.
RSS feed
|
|
|
|
|
|
Brian Delahunty wrote:
FxCOP can sometimes help there though.
Tried it, or only echoing the marketing brochure?
RSS feed
|
|
|
|
|
Stephane Rodriguez. wrote:
the marketing brochure?
Haven't seen any. Seriously.
Stephane Rodriguez. wrote:
Tried it
Yeah. But only recently. I've spent too much time tracking down issues when using COM and COM+ components in .NET applications and one of the guys in work was using FxCop so I pointed me in that area.... It's decent enough and it does help in a good few interop issues.
The main gripe I have with it is that it doesn't integrate into VS.NET... if it done that, and then donea quick scan each time as assembly was created then it would be excellent. But it's a free tool that has it's uses so I'm not going to complain too much about it.
Regards,
Brian Dela
http://www.briandela.com IE 6 required. http://www.briandela.com/pictures Now with a pictures section http://www.briandela.com/rss/newsrss.xml RSS Feed
|
|
|
|
|
Brian Delahunty wrote:
Haven't seen any (amrketing brochure). Seriously.
I am talking the MS weblogs and all that goes into that new marketing channel.
Brian Delahunty wrote:
It's decent enough and it does help in a good few interop issues.
I trust in you, unfortunately I can't figure out how an analyzer can show the issues with unmanaged code. By definition, it's not even possible for a managed code to be aware of anything that is unmanaged. For instance, a lot of the interop issues goes with what is supposed to be behind a LPTSTR. Such a parameter type doesn't say it's a [in] or a [out] parameter for instance. Since the caller never knows who holds the buffer, I think interop issues are pretty much doomed.
Also, given marshalling limitations when you are trying to interop complex structs, I wonder how FxCop can be of any help when you start using the interop services, allocating a buffer, and then start copying buffers back and forth.
Brian Delahunty wrote:
The main gripe I have with it is that it doesn't integrate into VS.NET
Yeah, I now think VS.NET lacks a lot of things, for instance the whole signing process. I can't think how Redmond manages to install 3.5 GB of binaries on some computer, and then fall short of such things.
Beyond me.
RSS feed
|
|
|
|
|
I have this drawing:
private System.Drawing.Graphics graphicsObj = null;
private System.Drawing.Pen penBlackWidth1 = new System.Drawing.Pen(System.Drawing.Color.Black,1);
private Point[] curvePoints = null;
private SolidBrush lightGrayBrush = new SolidBrush(Color.LightGray);
private Point point1;
private Point point2;
private Point point3;
private Point point4;
private SolidBrush blackBrush = new SolidBrush(Color.Black);
...................................................
try
{
graphicsObj = e.Graphics;
graphicsObj.DrawLine(penBlackWidth1, 45, 20, 175, 20);
graphicsObj.DrawLine(penBlackWidth1, 45, 20, 45, 120);
graphicsObj.DrawLine(penBlackWidth1, 175, 20, 175, 120);
graphicsObj.DrawLine(penBlackWidth1, 45,120,90,160);
graphicsObj.DrawLine(penBlackWidth1, 175, 120, 135, 160);
graphicsObj.DrawLine(penBlackWidth1, 90, 160, 135, 160);
graphicsObj.DrawLine(penBlackWidth1, 465, 335, 490, 335);
graphicsObj.DrawLine(penBlackWidth1, 580, 335, 605, 335);
graphicsObj.DrawLine(penBlackWidth1, 465, 335, 490, 335);
graphicsObj.DrawLine(penBlackWidth1, 580, 335, 605, 335);
graphicsObj.DrawLine(penBlackWidth1, 473, 345, 483, 345);
graphicsObj.DrawLine(penBlackWidth1, 473, 345, 478, 335);
graphicsObj.DrawLine(penBlackWidth1, 483, 345, 478, 335);
graphicsObj.DrawLine(penBlackWidth1, 587, 345, 597, 345);
graphicsObj.DrawLine(penBlackWidth1, 587, 345, 592, 335);
graphicsObj.DrawLine(penBlackWidth1, 597, 345, 592, 335);
point1 = new Point(592,335);
point2 = new Point(597,345);
point3 = new Point(587,345);
point4 = new Point(592,335);
curvePoints = new Point[]
{
point1,point2, point3, point4
};
graphicsObj.FillPolygon(blackBrush, curvePoints, FillMode.Alternate);
point1 = new Point(478,335);
point2 = new Point(483,345);
point3 = new Point(473,345);
point4 = new Point(478,335);
curvePoints = new Point[]
{
point1,point2, point3, point4
};
graphicsObj.FillPolygon(blackBrush, curvePoints, FillMode.Alternate);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
I want to fill the drawing with a color.
From buttom to top.
BUT the drawing must be filled accourding to a percent.
Is 50%, then only 50% of the drawing must be filled with the color.
Natural the fill must newer come outside the drawings edge.
Any help?
Thanks
|
|
|
|
|
correction:
if 50%, then only 50% of the drawing must be filled with the color.
|
|
|
|
|
Since you already have the coordinate points, create a region using these points and then use graphicsObj.ClipRgn() to set the clipping region. Then, you can draw a filled rectangle, without the fill color spilling out of the boundary.
Not so tough!!
|
|
|
|
|
Hi Shree
Can you give an example?
|
|
|
|
|
I'm having a problem which I'm not sure how to overcome. I've placed a listbox component inside a panel, that has autoscroll bars. When this listbox is partly outside the view of the panel, and it is clicked (i.e gets focus), the scrolling is adjusted so that the listbox is forced to be in view fully..
----------- CLICK => ------------
| panel | | |
| --| | -----|
| | |<-listbox | | ||
| --| | -----|
|<===== >| |< ======>|
----------- ------------
There are a couple of methods in the containercontrol that I believe have to do with this, one named ScrollActiveControlIntoView(). But of course it is private so I can't override it, can I?
Is there a suitable Windows message that I can capture and ignore in the wndproc for example, for this not to happen? What is the thread of action taken by windows when this happens, what messages are sent, etc. Does anyone know?
|
|
|
|
|
----------- CLICK => ------------
| panel | | |
| --| | -----|
| | |<-listbox | | ||
| --| | -----|
|<===== >| |< ======>|
----------- ------------
|
|
|
|
|
Nice ASCII!
Set AutoScroll to false . See the documentation for ScrollableControl.AutoScroll for more information.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
thanks!
about the autoscroll, if it is set to false, There will
be no scrollbars at all. (And I really want those, since
my view area is about 500 x 500 but the 'sheet' is about
2000 x 2000 ...)
What I don't want is the scroll to change just cause the
listbox gets input focus. I want it to get the focus when I
click it, cause I want to be able to control it with the the
keyboard, but I don't want the scroll to move
(basically because when I click the listbox I want to be able to drag it and move it. I then paint a border of it when it's being dragged. this border will mis-aligned cause I draw it from the coordinates of the listbox when mouse is clicked, but then the scroll changes and so does the coordinates of the view area, cause of the autoscroll...)
bummer, huh? =)
|
|
|
|
|
Does any of u guys know the link to good Regular
Expression Tutorial in .NET specailly CSharp.
|
|
|
|
|
I'm not familiar with any tutorials, but this article contains a handy application that can be used to test out various regular expressions. It's useful for generating the regular expression syntax to use in a program.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
|
Dear friends,
I've tried to make a simple application, and built it as an exe. But I got a problem , how can I prevent the application not to be re-opened if it has already been opened?
Could anyone point me the way??, need programming or just simple setting?
Thanks a lot
|
|
|
|
|
The best method is probably creating a "named" Mutex (in the System.Threading namespace). When your application first comes up, you try to claim the named Mutex, which is system-wide. If you can't claim it, another instance of the application is already running. The only thing you really have to do is make the name of the Mutex very unique. A good way to create something with a very unique name is to use a GUID.
So you do something like set a string up to be the Mutex name you want, like:
string mutexName = "...";
where you use a GUID in place of the ...
Then do something like:
bool weGotIt = false;
Mutex mutex = new Mutex(true, mutexName, out weGotIt);
if (weGotIt)
{
// Run like normal...
}
else
{
// Exit...another instance of the application already has it...
}
Let me know if I didn't explain this well or if you need more help.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Another way is to P/Invoke the FindWindow API in your Load event and if there is one instant of your application exist, exit the program.
Mazy
No sig. available now.
|
|
|
|
|
Using a Mutex is by far the best way, because they are atomic (an ATOM registered in the system). Using FindWindow relies on a window class name and / or a caption, which could already exist whether it's the correct application or not, or the caption for your application might be dynamic so a running instance won't be found by FindWindow . It works for many cases, but not all.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thank you for all of your replies.
But could you give me a full example simply show me that how to use "Mutex". Is it the traditional way to do?
Thank you
|
|
|
|
|
Kentamanos already did above. You acquire a Mutex with the first instance and the second instance (or more) can't acquire it so you exit the application:
string mutexName = "some unique string";
bool acquired;
new Mutex(true, mutexName, out acquired);
if (acquired)
{
Application.Run(new MainForm());
}
else
{
Application.Exit();
} Optionally, if you don't acquire the Mutex , you can grab the command line parameters (like a filename) and force the existing process to open a new document (or set focus to the existing document). There are plenty of examples of this here on CodeProject and on the 'net.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
What do you mean?
Kentamanos has posted it.
Thank You
Bo Hunter
|
|
|
|
|
i am a beginner really and i thaught i had the right program and i want to know if the c# builder tool was free and if it it is free if some1 could email it to me
|
|
|
|
|