|
Tom Larsen wrote:
You are trying to circumvent the strongly typed system in .Net. You should write a shim object that behaves like a DataView or a BinaryWriter through that shim object/interface. This shim will have Close and any other logic to call the right things.
Yeah I figured that's what would be suggested. I hate to write an extra object just for this simple problem, but I suppose it would be better than writing it out as previously posted.
Thanks for the replies Tom and Heath.
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
Why do you care about a Close method? If you want to make sure something's closed, then you're going about it the wrong way. Instead, accept an IDisposable and call Dispose on the object. It doesn't matter what the implementation is, then. IDisposable is implemented by objects that have to clean up resources, like streams and the like. It will close any handles that are open for you. THAT's what you need to worry about if I follow your train of thought correctly. See the documentation for the IDisposable interface in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Simply put: System.Windows.Forms.Form does not implement IFoo . I'm not sure why you thought Form did. Is it because of Invalidate (which Form gets from Control no less)? Again, Control.Invalidate() has nothing to do with IFoo.Invalidate() at all. There is no possible cast. Period.
|
|
|
|
|
Tom Larsen wrote:
Simply put: System.Windows.Forms.Form does not implement IFoo. I'm not sure why you thought Form did.
Right, I understand it doesn't explicitly implement IFoo. In a way though, because it implements all methods of IFoo, it *kind of* implements it, in that it implements all the methods of IFoo without actually implementing it explicitly.
And again to stress, I know I can't cast a Form to IFoo. The original post was simply a question of ~why~ .NET won't let me do it, and to see if there were any better ways of conquering the said problem.
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
Judah H. wrote:
n a way though, because it implements all methods of IFoo, it *kind of* implements it, in that it implements all the methods of IFoo without actually implementing it explicitly.
Nope, just because you write an interface that defines methods that another class has does not make a binding contract between the existing class and your interface. Classes must be aware of the interfaces they implement at compile time, this is why you will get compiler errors if you write some class and tell it to implement some interface and you do not providing a said implementation. You can't write a class that implements some method and then at runtime tell it that that implementation belongs to an interface that it wasn't assigned to the class at compile time.
- Nick Parker My Blog
|
|
|
|
|
Hi.
<br />
bool FrmIsOpen = false; <br />
<br />
for (int i=0; i < this.MdiParent.MdiChildren.Length; i++) <br />
{ <br />
if (this.MdiParent.MdiChildren[i].GetType() == typeof(FrmPassword)) <br />
{ <br />
FrmIsOpen = true; <br />
break; <br />
} <br />
}<br />
<br />
if (!FrmIsOpen) <br />
{ <br />
FrmPassword r = new FrmPassword(); <br />
r.MdiParent = this;<br />
r.Show(); <br />
} <br />
An unhandled exception of type 'System.NullReferenceException' occurred in CLINICINFORMATIONSYSTEM.exe
Additional information: Object reference not set to an instance of an object.
the error's pointing to the line that has been bold...i dont understand what is it trying to say?....
CODER
|
|
|
|
|
It's trying to tell you that something is null; this.MdiParent or MdiParent.MdiChildren is null. Check for that condition before entering the loop.
---------------------------
He who knows that enough is enough will always
have enough.
-Lao Tsu
|
|
|
|
|
Hi,
Im sorry Judah, im a beginner...i would appreciate it if you could show me how i can do that.
thx in advance
CODER
|
|
|
|
|
bool FrmIsOpen = false;
if(this.MdiParent != null && this.MdiParent.MdiChildren != null)
{
for (int i=0; i < this.MdiParent.MdiChildren.Length; i++)
{
if (this.MdiParent.MdiChildren[i].GetType() == typeof(FrmPassword))
{
FrmIsOpen = true;
break;
}
}
}
if (!FrmIsOpen)
{
FrmPassword r = new FrmPassword();
r.MdiParent = this;
r.Show();
}
---------------------------
He who knows that enough is enough will always
have enough.
-Lao Tsu
|
|
|
|
|
My first question would be where is this code sitting?
Is it in a child form or an MDIParent? It looks like a parent form has this code, in which case the parent form has no MDIParent. This reference would be null, and therefor, your reference to 'this.MdiParent.MdiChildren.Length' would return null. If this code is in a parent form, then your reference should be this.MdiChildren.Length.
RageInTheMachine9532
|
|
|
|
|
its in a parent form. i tried editing the code your way..but it is still able to open up two same forms...
<br />
bool FrmIsOpen = false; <br />
<br />
if(this.MdiParent != null && this.MdiChildren != null)<br />
{<br />
for (int i=0; i < this.MdiChildren.Length; i++) <br />
{ <br />
if (this.MdiParent.MdiChildren[i].GetType() == typeof(FrmPassword)) <br />
{ <br />
FrmIsOpen = true; <br />
break; <br />
} <br />
}<br />
}<br />
if (!FrmIsOpen) <br />
{ <br />
FrmPassword r = new FrmPassword(); <br />
r.MdiParent = this;<br />
r.Show(); <br />
} <br />
CODER
|
|
|
|
|
OK. The loop now runs but your references in your if statement are still screwed up. Use this instead:
bool FrmIsOpen = false;
if (this.MdiChildren.Length > 0)
for (int i=0; i < this.MdiChildren.Length; i++)
{
if (this.MdiChildren[i].GetType() == GetType(FrmPassword))
{
FrmIsOpen = true;
break;
}
}
}
if (!FrmIsOpen)
{
FrmPassword r = new FrmPassword();
r.MdiParent = this;
r.Show();
}
The first bolded statement was changed because 'this.MDIParent' will always return null if 'this' is an MDIParent. This was changed to checking if the MDIChildren collection has anything in it. In the second bolded statement, the 'typeof()' reference was changed to 'GetType()'. If you have to, you could change this to 'Type.GetType()'. This should take care of your problem.
RageInTheMachine9532
|
|
|
|
|
hey guys,
well this is my problem. I am trying to read a text file ,with information such as these three lines, insert it into the program, then seperate them into a usable format for use. There are about 1000 such lines, but speed is not neccessarily an issue. Thanks for the help.
501,Red_Potion,Red Potion,0,50,,70,,,,,10477567,2,,,,,
502,Orange_Potion,Orange Potion,0,200,,100,,,,,10477567,2,,,,,
503,Yellow_Potion,Yellow Potion,0,550,,130,,,,,10477567,2,,,,,
i was kinda wondering if there was same way to use a multidimentional array where the rows are the text files lines and the columns are the different values.
|
|
|
|
|
how about:
ArrayList table = new ArrayList;
SreamReader txtFile = new StreamReader("myfile.txt");
while ((string reader = txtFile.ReadLine()) != null) {
table.add(reader.Split(","));
}
txtFile.Close();
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
|
|
|
|
|
Hi!
does anyone have some experience with Jpeg2000 and .NET ???
can someone give me some code samples how to compress a picture to
Jpeg2000 with .NET ???
and how to show a Jpeg2000 picture although the picture is not loaded
complete??? (show the Jpeg2000 picture with a lower quality).
how to send (upload) DICOM Header of a Jpeg2000 picture???
best regards,
gicio
|
|
|
|
|
Hi!
does anyone have some experience with BITS
(Background Intelligent Transfer Service) and .NET ???
can someone give me some code samples how to use BITS with .NET ???
regards,
gicio
|
|
|
|
|
Check MSDN, there are several example articles there.
- Nick Parker My Blog
|
|
|
|
|
|
Hi!!
does anyone some experience with BITS
(Background Intelligent Transfer Service) and SSL and .NET ????
can someone give me some code samples how to use it?
regards,
gicio
|
|
|
|
|
I have several devices on a local network that I talk to. But if a device is turned off, .Connect takes more than 30 seconds to return. How do I get .Connect to timeout, within a second, if the device is not on the network?
Brian
|
|
|
|
|
Socket.SetSocketOption() method
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
I set the SocketOptionName.SendTimeout and SocketOptionName.ReceiveTimeout, but it didn't affect the Connnect timeout.
Brian
|
|
|
|
|
Hi, all!
How can I crate TextBox which would display 'circles' instead of '*' in WinXP?
Currently I have TextBox with PasswordChar set to '*' because of I do not know how else I can say that this is a PasswordBox.
I enabled Visual Styles through manifest but it still shows '*'
Thanks.
Regards,
alexx.
|
|
|
|
|
you can use the dot character (copy and paste one of these)
• ( U+0222 arial)
● ( U+25CF times new roman)
or any other character in the Windows' CharactersMap (unicode section)
|
|
|
|
|
Hello, Claudio!
But in that case I'll got the same char in Win2k and I do not want to.
Thanks.
Regards,
alexx
|
|
|
|