|
The compiler is right because private means that only the class that has the method/property/field can use it. No other class is permitted access including any class derived from it. And virtual tells the compiler to expect derived classes to override it. Therefore making a method private and virtual would be utterly pointless.
Hiding the method kind of goes against the grain of Object Orientation. I remember years ago my OO lecturer at University going on about that. When you create derived classes you are creating specialisations of the base. You should never be taking anything away from the base, just adding new methods and specialising existing ones.
I would suggest that you re-examine your class design and work out if there is a way to better design the classes so that you are not having to take away the functionality in the base.
Alternatively you could explain a bit about your design and maybe some people here can help you re-work it.
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|
|
Thank you for your replies.
The reason why I want to hide the parent class is because I need more data for the child.
By the way the parents class is built in, I can't change it: DevExpress.XtraBars.PopupMenu
I want the user to call the following function that is implemented by the child
public void ShowPopup(System.Drawing.Point p, File selectedFile, Folder selectedFolder, Folder destinationFolder)
instead of the original
public void ShowPopup(System.Drawing.Point p)
I could have two separate calls: SetFileData(selectedFile, selectedFolder, destinationFolder) and then ShowPopup(p), but there will be big bad problems if the user forgets to make the first call.
Elena
|
|
|
|
|
I assume by "user" in this case you mean another "developer". To avoid confustion, I'll use the term "developer" to mean a person that writes code, and "user" to mean a person that uses software applications.
Okay, so you have a third party component that exposes a method called ShowPopup(), you want to derive a class from it and extend the functionality by implementing your own ShowPopup with extra parameters. In the new derived class the base.ShowPopup() will work correctly so long as the developer has called SetFileDate(). Right?
My advice is to not mollycoddle other developers, defend against users doing weird things but not developers. Document that there is an extended version of ShowPopup() with the extra parameters which is to be used in preference for this class. Also document that if the original ShowPopup is used that the SetFileData() must be called first for this class. Anything else is wrong and will cause an exception to be thrown (remember that is what exceptions are for).
Here's an example of something designed in a similar way to what I've described: What happens if you have an array with 5 elements and you try and get the 10th element? An exception is thrown. Why? Because that was a dumb thing to do.
If it helps, you should override the ShowPopup() [You mentioned it was virtual already] and check for the prensence of the file data and throw the relevant exception if it doesn't exist. (If you don't have a relevant exception, create a new exception class)
Begin Rambling Nostalgia: I remember back in the days where I did C++ development the documentation was full of remarks like "The first parameter takes an integer between 1 and 12, for any other supplied value the results are undefined". In other words, "Garbage In, Garbage Out". In reality the "undefined" results could mean anything from invalid calculations to the whole application crashing. At least now there are exceptions so that invalid/missing inputs or expected preconditions can be thrown out and dealt with properly.
I hope this helps.
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|
|
You can't make a public function in a parent class private in a child child class. if you could, it would break polymorphism since the inherited class would not support the parent's "interface" or contract. What you can do is override ShowPopup so that is does nothing.
|
|
|
|
|
Mailing Lists wrote:
What you can do is override ShowPopup so that is does nothing.
You could do. But that sounds really messy and horrible because it could be that some time later a developer is doing something and expecting a pop up and then spending ages trying to work out why a popup wasn't happening. Then I'd get really .
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|
|
I would override the method and throw an NotSupportedException . And document that the method is not supported. This keeps the developers out of confusion. Maybe like this:
throw new NotSupportedException("This method is not supported by this class.
Use the overload ShowPopup(Point, File, Folder, Folder) instead.")
|
|
|
|
|
elena12345 wrote:
Any ideas how I could hide this function?
Encapsulation
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
I'm sorry if my question sounds silly:
Can i bind a property of a control to another property of
another control?
I´m trying to bind the Text property of a Label control to
a custom property of a custom control (derived from Control). What should I do?
My goal is to write something like:
Label.DataBindings.Add("Text",CustControl.Property, "");
Thanks.
|
|
|
|
|
Yes you can, and the code you wrote should work. This is managed by the PropertyManager , as opposed to the CurrencyManager that's used for data-type data-binding. See the documentation for the PropertyManager class for more details.
-----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-----
|
|
|
|
|
I think you mite need to apply the DataBindableAttribute to the property.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
When coding in the editor, I get intellisense hints with the description I made for my objects, functions and parameters. This I get automatically, the only think you must do is to use the documentation tags.
Unfortunatelly, this works only within a single project. When using the documented component in the client application, I do get only class/method with names and function signatures without any documentation. The assembly produced by VS.NET simply lacks the documentation I prepared.
I tried to compile the project using /doc directive hoping that the file gets compiled into the assembly somehow (although there is no explicit mention about this functionality in MSDN documentation). Actually, I'm lacking any information how the C# documentation offers and how compile the documentation into the assembly. Do you know some resource?
What's the heck? Perhaps I should search somewhere else than in VS.NET?
Thanks for help
Vasek
VB6, C#, MS DNA, MS.NET
Software Developer
|
|
|
|
|
You must use the documentation syntax and either use the /doc:AssemblyName.xml flag on the command-line compiler, or set the same filename in the Documentation setting in the project's configuration dialog (right-click on the project and select Properties).
These XML files should be in the same directories as the assemblies. Note, they are NOT added to the assembly. If you want to generate HTML Help or Help 2 help files out of them, see the NDoc project.
-----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-----
|
|
|
|
|
Jeez Heath, do you ever sleep? Don't you have work to do somewhere? I thought I could beat you to this one...but you out-posted me by one minute.
When I can talk about 64 bit processors and attract girls with my computer not my car, I'll come out of the closet. Until that time...I'm like "What's the ENTER key?"
-Hockey on being a geek
|
|
|
|
|
Heath Stewart wrote:
/doc:AssemblyName.xml
Thanks for reply. This I did but still not have the documentation in the Intellisense. How do I tell to IDE that it should use that file?
Vasek
VB6, C#, MS DNA, MS.NET
Software Developer
|
|
|
|
|
Remember that those XML files must be in the same directory as the assemblies you're referencing. This is how VS.NET and other IDEs (or some tools out there) find the necessary documentation. So, if you move your assemblies out of the target output directories, make sure you take the XML documentation files with them.
-----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-----
|
|
|
|
|
Vasek wrote:
hoping that the file gets compiled into the assembly somehow
That would be nice, wouldn't it?
Actually what happens is that the XML comments that you wrote get compiled into an entirely separate XML file in your bin directory with the same name as your assembly. Then VS.NET uses that information at design time to populate the help cache. If you move the assembly, you also need to move the XML file with it.
Hope that helps.
When I can talk about 64 bit processors and attract girls with my computer not my car, I'll come out of the closet. Until that time...I'm like "What's the ENTER key?"
-Hockey on being a geek
|
|
|
|
|
I wonder..
Would it be possible to add the documentation.xml-file to your project? This would only work when and if the Xml-file is generated before the assembly is compiled.
- Daniël Pelsmaeker
|
|
|
|
|
Hello,
I'm trying to decide what is the best way to store my application's location, size, state and also a bunch of other options such as font, color, recently viewed files, etc.
Should I store the information in the registry or in some type of a file? Do people still use .ini files for saving settings anymore? In an older version of my application, I stored the information in a .ini file, but I'm not sure if that is the best way to do it.
Thanks in advance,
Blake
|
|
|
|
|
If maintaning xcopy deployment is a factor you should avoid the registry. Otherwise storing it in an ini or other type of file is probably your best solution.
|
|
|
|
|
Try my article: An extension for a Configuration Settings class in .NET[^], it covers what you are asking for.
-Nick Parker
Last time I checked, all programmers have selective ignorance. I know nothing about 3D graphics. I know a lot about COM. VB gets under people's skin because one can be ignorant of computer architecture and ASM and still get a lot done. - Don Box
|
|
|
|
|
Hi there!
Recently I encountered a surprising effect of the C# language. I wrote the following lines:
public class A
{
public string name;
}
public class X
{
public static void Main()
{
A a1 = new A();
A a2 = new A();
A a;
A _a;
a = a1;
_a = a;
_a.name = "TTT";
//ok, variable "a1" is modified
a = a2; //change the reference target to instance "a2"
_a.name = "SSS";
//?!?, still variable "a1" is modified, although
//the reference is pointing to variable "a2" !!!
_a = a;
_a.name = "SSS";
//ok, now variable "a2" is modified
}
Om, what's happening here? It should be possible to create references to a reference in C#? Is there any optimization action done in the background, that translates a "ref to ref" to a "ref", what would explain the ignoring of the changed ref variable?
Greetings,
Matej
}
Balkanese
|
|
|
|
|
A Reference is just a fancy word for a pointer. Consider...
A a1 = new A();
A a2 = a1;
A a3 = a2;
So everything is pointing to the same instance of the class A
Now...
a2 = new A();
What do you think happens? ...
a1 still points to the first instance
a2 now points to the second instance
a3 still points to the first instance
Why? Because a3 was never told to point to anything else. When a3 was created it was told to point to the first instance, not to a2 - In other words it was told to point to whatever a2 was currently pointing to. a2 is still at liberty to point to something else in the future.
Does this help clear things up?
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|
|
Yes, thank you!
I was assuming something like this. So this means there is no way to let a reference point to a reference instead to the instanced object itself in C#, like it was possible in C++?
This would be a great thing e.g. for a list (ArrayList, etc.). If the listelements would point to a reference variable not to an instance I would just have to change that ref variable in order to change all list elements with that target at one time!
But it seems, that if I want to do so, I will have to change the instantiated object itself, won't I?
Matej
|
|
|
|
|
Why does VS.NET 2003 delete everything from the debug directory, when building a solution? I can't run my application, because when I build it, app.exe.config is removed from the debug directory.
Please HELP
|
|
|
|
|
This is the behavior of practically any build system - it removes the old stuff. VS.NET does have an undocumented (at least, from what I've read) feature where any file named app.config in your project gets renamed appropriately and moved to your target output directory. You could either add this file to your project and make sure the settings are correct in that, or have a backup app.exe.config file in your target output directories that you can copy to the appropriate name after building.
-----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-----
|
|
|
|