|
Actually, the IComparable interface isn't going to help you. The CompareTo() method returns an int. It's for sorting lists.
You should however, use the "is" keyword in order to find out if it "is" an instance of that class. Don't use GetType() typeof() or even CompareTo(). Let's say you had a function that looked like this:
public void Cast(object obj)
{
if(obj is OneType)
{
OneType castedType = (OneType)obj;
{
else if(obj is AnotherType)
{
AnotherType castedType = (AnotherType)obj;
{
return;
}
If you really want dynamic casting, this is the way to do it. Using IComparable is not.
Hope that's clearer now.
Hey, what can I say? I'm a chick magnet...a babe conductor...a logarithm for the ladies.
-Strong Bad from HomeStarRunner.com
Essential Tips for Web Developers
|
|
|
|
|
mgarwood wrote:
I would like to be able to do some sort of "dyanmic cast" on the data and call the appropriate CompareTo() method.
Something like this might help.
int Compare(object obj1, object obj2)
{
IComparable icom = obj1 as IComparable;
if (icom != null && obj2.GetType() == obj1.GetType())
return icom.CompareTo(obj2);
return int.MinValue;
}
MyDUMeter: a .NET DUMeter clone
|
|
|
|
|
Will this work with primitive types as well (i.e. 'int', 'char', 'bool', 'short', long')?
If this will work this is the easiest and cleanest way. Before I got some suggestions I was leaning torwrds delegates but didn't really want to go there.
Thanks
|
|
|
|
|
hello to list
any assistance much appreciated.
i apologise if this message loads slowly (received a warning when i sent). i live way out back, very slow connection, and i get email longer than this no problem)
why did the one project i did compile include syntax
different to the text book example? (staugaard, jr. structured and object oriented techniques, 2nd edition)
using borland 5.5.1 free command line tools with a command promt screen setup for me be a student list advisor so i type in 'complink <filename> to compile. i don't want to bother him further on this matter. couldn't figure out how to get a project to compile with borland 4.5, but have succedded in getting one to run with 5.5.1. i thought all i would have to do is use the same #include, #endif, etc, and all would be well. i think the enum is wrecking things in some small part, i can't find any information to show me rules for using enum's in structs. this code is probably a bit cut up by now.
you may have to fix the word wrap
you may assume i am rather green at this
/* *************************************** */
/* Yahtzee header file: */
#ifndef YATZ_H
#define YATZ_H
struct Play
{
private:
public:
int Score[ScoreMax+1];
int Dice[DiceMax+1];
void DisplayScoreCat(ScoreCat Cat);
void DisplayDice();
void Throw();
void Initialise();
};
#endif
/* *****************************************8 */
/* main file */
#include <iostream>
#include <iomanip>
#include <stdlib>
#include <time>
using namespace std;
#include "Yahzt.h"
const int ScoreMax=17;
const int DiceMax=5;
int main()
{
enum ScoreCat {Ones, Twos, Threes,
Fours, Fives, Sixes,
Three_of_a_Kind, Four_of_a_Kind, Full_House, Small_Straight,
Large_Straight, Yahtzee, Chance, Bonus, Upper_Total, Lower_Total,
Grand_Total};
ScoreCat Cat;
Play Game; // declare Game object
Game.Initialise();
time_t t;
srand((unsigned) time(&t));
cout<<"\n\n\t\tYatsee Game "
<<"\t\tScoring Catagories \n\n";
for(Cat = Ones; Cat <= Full_House; Cat =(ScoreCat) (Cat+1))
{
cout<<"\t\t"<<(Cat+1);
Game.DisplayScoreCat(Cat);
cout<<"-"<<Game.Score[Cat];
if(Cat<=3)
{
cout<<"\t"<<(Cat +10);
}
if(Cat<=7 )
{
Game.DisplayScoreCat(Cat+9);
cout<<"-"<<Game.Score[Cat+9];
}
cout<<endl;
}//end for
cout<<"\n\n";
Game.Throw();
Game.DisplayDice();
}
#include "Yahtz.cpp"
/* ***************************************** */
/* function file */
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;
#include "Yahtz.h"
void Play::DisplayScoreCat(ScoreCat Cat)
{
switch(Cat)
{
case Ones: cout<<setw(18)<< "Ones"; break;
case Twos: cout<<setw(18)<< "Twos"; break;
case Threes: cout<< setw(18)<< "Thees"; break;
case Fours: cout<< setw(18)<< "Fours"; break;
case Fives: cout<< setw(18)<< "Fives"; break;
case Sixes: cout<< setw(18)<< "Sixes"; break;
case Three_of_a_Kind: cout<< setw(18)<< "3 of a Kind"; break;
case Four_of_a_Kind: cout<< setw(18)<< "4 of a Kind"; break;
case Full_House: cout<< setw(18)<< "Full House"; break;
case Small_Straight: cout<< setw(18)<< "Small Straight"; break;
case Large_Straight: cout<< setw(18)<< "Large straight"; break;
case Yahtzee: cout<< setw(18)<< "Yahtzee"; break;
case Chance: cout<< setw(18)<< "Chance"; break;
case Bonus: cout<< setw(23)<< "Bonus"; break;
case Upper_Total: cout<< setw(23)<< "Upper Total"; break;
case Lower_Total: cout<< setw(23)<< "Lower Total"; break;
case Grand_Total: cout<< setw(23)<< "Grand Total"; break;
cout<<"\t\tUnknown day"; break;
}
}
void Play::DisplayDice()
{
cout<<"\tThe 5 dice are :\n";
for(int i=0;i<5;i++)
{
cout<<Dice[i];
}
char console[4] [42]=
{
" 1 2 3 4 5 \n",
"----- ----- ----- ----- -----\n",
"| | | | | | | | | |\n",
"----- ----- ----- ----- -----\n"
};
for(int i=0; i<4; i++)
{
for(int j=0; j <42; j++)
{
if(j==0)
cout<<"\t\t";
if(j==2&&i==2)
{
console[i][j]=Dice[0];
}
if(j==11&&i==2)
{
console[i][j]=Dice[1];
}
if(j==20&&i==2)
{
console[i][j]=Dice[2];
}
if(j==29&&i==2)
{
console[i][j]=Dice[3];
}
if(j==38&&i==2)
{
console[i][j]=Dice[4];
}
cout<<console[i][j];
}
}
}
void Play::Throw()
{
for(int i=0; i<5; i++)
{
Dice[i]=(1+rand()%6);
}
}
void Play::Initialise()
{
for(int i=0; i<ScoreMax; i++)
{
Score[i]=0;
}
for(int i=0; i<DiceMax; i++)
{
Dice [i]=0;
}
}
/* **********************************************
error messages generated:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
Yahtzmain.cpp:
Error E2209 Yahtzmain.cpp 12: Unable to open include file 'Yahzt.h'
Error E2451 Yahtzmain.cpp 27: Undefined symbol 'Play' in function main()
Error E2379 Yahtzmain.cpp 27: Statement missing ; in function main()
Error E2451 Yahtzmain.cpp 29: Undefined symbol 'Game' in function main()
Error E2293 Yahtz.h 15: ) expected
Error E2147 Yahtz.cpp 12: 'ScoreCat' cannot start a parameter declaration
Error E2316 Yahtz.cpp 13: 'Play::DisplayScoreCat(int)' is not a member of 'Play'
Error E2206 Yahtz.cpp 35: Illegal character '\' (0x5c)
Error E2206 Yahtz.cpp 35: Illegal character '\' (0x5c)
*** 9 errors in Compile ***
*/
|
|
|
|
|
You've posted this in the C# forum.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
It'd probably be fairly easy to make a bot that'd post random stupid VB questions, and nobody would probably ever notice - benjymous - 21-Jan-2003
|
|
|
|
|
please educate me.
i thought C# meant c, and some extention, like '++'
where should i have posted this query?
i thought i mentioned i am using borland 5.5.1,
i understood borland uses a much stricter form of c++ and vb is mainly for windows apps.
do you just hate c++, why? in my small understanding of the matter it seems to be the pick.
i still want to know what i'm doing wrong and c++ is all i know.
thank you for your response.
|
|
|
|
|
You should go to the Visual C++ forum. They deal with all sorts of C++ problems in there...not just Microsoft related ones. C# is a new language by Microsoft made especially for the .NET platform and while it may look similar to C++, it isn't. Hope that clears things up.
Hey, what can I say? I'm a chick magnet...a babe conductor...a logarithm for the ladies.
-Strong Bad from HomeStarRunner.com
Essential Tips for Web Developers
|
|
|
|
|
Funny joke.
|
|
|
|
|
|
just ignorance, borland was free, better than what i had. now i am less ignorant.
|
|
|
|
|
Okay, I'm trying to parse and HTML page, and grab some text out of a table.
Thing is I can't remember how to grab a block of text across mutiple lines. Note I'm not talking about doing a multiple match.
As an example I would do something like the following to grab all the text inside the font tag :
<FONT.*>(.*)</.*>
for
<FONT size="2">
Something<BR>
Some more text<BR>
Another Line<BR>
Bla Bla Bla
<BR>
</FONT>
I know the . operator matches eveything except a new line character \n. I need the thing that includes the new line character or some combination in a []
Help!!
I love regexes but I'm damn rusty.
|
|
|
|
|
Two comments:
1) Go to http://www.csharp.net, and on the left pane you'll find Regular Expression Workbench. Download it, find the .MSI in the archive and install it.
2) You need to set the multiline (or is it singleline option) on your regex. That will make "." match any character including \n, which should give you what you want. You can try this in the workbench easily.
|
|
|
|
|
I have a namespace (NetworkManagement) that subclasses a
combobox and a treeview and loads each with some
directory info for a given PC....
I'm instantiating these controls from another namespace
(NetworkManagement.Demo) which contains the Windows Form
object that contains a standard (non-subclassed) listview
that I need to update based on a click in the treeview in
the NetworkManagement namespace.....
The two namespaces live in different assemblies... eash assembly lives in a project that is in a single solution... so the solution contains a Windows Form project and an assembly project with subclassed controls.
I need to be able to access the listview in the Windows Form from the
subclassed treeview in the other assembly... can someone clue me in as to how
this can be done?
|
|
|
|
|
|
thanks for the reply, but I'm not sure how to access the Form's controls programmatically... the name of the form object is ServerComboBoxForm, inheriting from System.Windows.Forms.Form. It contains the subclassed controls that I mentioned earlier, but the subclassed treeview needs to be able to talk to the form's listview, so I need a way to do this from the the assembly that contains the subclassed treeview...
thanks for any help...
|
|
|
|
|
Hi, all!
Would you like to help me?
Have the folow:
I want to create COM+ component with help c#, so, it will use the external(usual) dll-file(my.dll), where contents some logic (com-objects).
This dll good work in usual application, when add it as reference - all ok.
(a have not source for this dll file)
But when i try to link up it in my developed com+ app., - got folow answer from compiler:
"Assembly generation failed -- Referenced assembly 'name of my.dll' does not have a strong name"
is it have not 'strong name'????
i try the next:
al /out:my.dll "?" /keyfile:my_dll.snk
but it don't want to work... i do not understand want is this "?"
and is it right way to solve this problem? and what i must do in this case?
in any case thx.
|
|
|
|
|
Hi there guys,
1. I have owner-drawn list boxes on my form, everything draws alright and perfectly - but it flickers... so does anybody have the perfect solution for flicker free owner draw?
2. The drawing doesn't show well after drawing it the first time and after scrolling up... what to do?
Update() doesn't work well in this case, and I know it does redraw.
Thanks a lot!
I owe you all one...
---
Yuval Kaplan
http://www.srcKeep.net/[^]
|
|
|
|
|
|
Hmm, sorry - I didn't create my own control and the drawing flickers upon scrolling, and in the demo of the above article it flickered when I scrolled.
Anyway, the major problem I have is the non-updating areas... and I did call Invalidate() or Update() or Refresh(), and the DrawItem proc was entered into. Any suggestions?
Thanks!
---
Yuval Kaplan
http://www.srcKeep.net/[^]
|
|
|
|
|
Hello,
I'm extensively using the Webbrowser control and everything is almost fine...
Actually I found a strange problem.
I crawl to a page containing the following code:
When using the IHTMLAnchorElement and asking for the 'href' property, I get the following result:
http://pubs.mgn.net/event.ng/Type=click&FlightID=6121&AdID=17734&TargetID=1165&Segments=108,143,292,365,382,1035,1227&Targets=273,1165&Values=31,43,51,60,72,81,91,100,110,150,206,213,237,474,601,625,763,934,938,940,1007,1009,1046,1253,1282,1448,1907,1963,2018&RawValues=&Redirect=http://www.fnac.com/Shelf/article.asp?PRID=1391122&Origin=2003.2.10.12.24.24.0&OriginClick=yes
But If I issue an HTTP GET request, I get a 404 error (after redirection, the web server is a Netscape Entreprise Server).
I know that if I use this URL instead (like IE does !), I will work:
http://pubs.mgn.net/event.ng/Type=click&FlightID=6121&AdID=17734&TargetID=1165&Segments=108,143,292,365,382,1035,1227&Targets=273,1165&Values=31,43,51,60,72,81,91,100,110,150,206,213,237,474,601,625,763,934,938,940,1007,1009,1046,1253,1282,1448,1907,1963,2018&RawValues=&Redirect=http:%2F%2Fwww.fnac.com%2FShelf%2Farticle.asp%3FPRID%3D1391122%26Origin%3D2003.2.10.12.24.24.0%26OriginClick%3Dyes
The difference is that the second URL has HTML decoded all & but kept all URL encoded characters.
Using the debugger I found that because the WebBrowser control is misparsing the anchor, I also get wrong values for the 'search' property (of IHTMLAnchorElement) and so on.
Is it a bug ? What can I do to deal with this problem and get a perfectly parsed URL ?
Regards,
R. LOPES
Just programmer.
|
|
|
|
|
Hello,
Repost because the first URL was translated by the message board.
I'm extensively using the Webbrowser control and everything is almost fine...
Actually I found a strange problem.
I crawl to a page containing the following code:
<br />
<A href=\"/event.ng/Type=click&FlightID=6121&AdID=17734&TargetID=1165&Segments=108,143,292,365,382,1035,1227&Targets=273,1165&Values=31,43,51,60,72,81,91,100,110,150,206,213,237,474,601,625,763,934,938,940,1007,1009,1046,1253,1282,1448,1907,1963,2018&RawValues=&Redirect=http:%2F%2Fwww.fnac.com%2FShelf%2Farticle.asp%3FPRID%3D1391122%26Origin%3D2003.2.10.12.24.24.0%26OriginClick%3Dyes\" target=_blank><IMG height=63 alt=\"\" src=\"http://pub.club-internet.fr/Netgravity/Fnac/100x63_massive_070203.gif\" width=100 border=0></A><br />
When using the IHTMLAnchorElement and asking for the 'href' property, I get the following result:
<br />
http:
But If I issue an HTTP GET request, I get a 404 error (after redirection, the web server is a Netscape Entreprise Server).
I know that if I use this URL instead (like IE does !), I will work:
<br />
http:
The difference is that the second URL has HTML decoded all & but kept all URL encoded characters.
Using the debugger I found that because the WebBrowser control is misparsing the anchor, I also get wrong values for the 'search' property (of IHTMLAnchorElement) and so on.
Is it a bug ? What can I do to deal with this problem and get a perfectly parsed URL ?
Regards,
R. LOPES
Just programmer.
|
|
|
|
|
Hi,
I've created an "DLL" to place some controls of my own, but when I "include" them in a normal app ( I inherit a control to my own control), then it gives me the following error:
"The Item xxxx.resx does not exist in the project directory, it may have been moved renamed or deleted"
Do I have to import the resource of the base control to my windows form application project ? I think I'm doing something wrong here...
Thanks in advance, greetings
Braulio
|
|
|
|
|
From the minimum requirements it seems that FileSystemWatcher does not work with 98 or ME. So, I'm thinking about writing my own version that does. Any ideas? I guess detecting new files or files that have changed with different sizes is easy. How about detecting changes in files where the new and old file size is the same? Is checking the various date stamps the only way?
Thanks in advance
Andy
|
|
|
|
|
|
Hi
need some serious help with a regex pattern..
i have the following expression:
Regex regex = new Regex(@"(^(aa)*(?!a)(b))", RegexOptions.ExplicitCapture);
what it does (partially) and is intended to do is to match only when there is an EVEN number of A infront of B
like:
b -> match
ab -> no match
aab -> match
aaab -> no match
aaaab -> match
aaaaab -> no match
etc..
so far so good
what i want is to make it only return the "b" when a match is found.
and also i want it to behave the same way when there is text infront of the pattern , like:
helloB -> match
helloAB -> no match
helloAAB -> match
helloAAAB -> no match
anyone?
//Roger
|
|
|
|
|