Jump to content
Xtreme .Net Talk

rbulph

Avatar/Signature
  • Posts

    398
  • Joined

  • Last visited

Everything posted by rbulph

  1. It's a sort of information system based on an object model. Each plug in can give information about the objects passed to it in its own way. Perhaps the following example will make things clearer. As you'll see, I've come up with two possible solutions to the Select Case issue, but it would still be good to have a neater one if you can think of it. 'Begin Class Library Public Class BaseClass End Class Public Class class1 Inherits BaseClass End Class Public Class class2 Inherits BaseClass End Class Public Class class3 Inherits BaseClass End Class Interface IClassHandler Sub HandleClass(ByVal X As BaseClass) End Interface 'End Class Library 'Begin PlugInA Public Class PlugInA Implements IClassHandler Public Sub HandleClass(ByVal X As BaseClass) Implements IClassHandler.HandleClass Select Case X.GetType.Name Case "class1", "class2" MsgBox("This is the situation for Class1s and Class2s") Case "class3" MsgBox("This is the situation for Class3s") End Select End Sub End Class 'End PlugInA 'Begin PlugInB Public Class PlugInB Implements IClassHandler Public Sub HandleClass(ByVal X As BaseClass) Implements IClassHandler.HandleClass Select Case X.GetType.Name Case GetType(class1).Name MsgBox("Here's some info about Class1s") Case GetType(class2).Name MsgBox("Here's some info about Class2s") Case GetType(class3).Name MsgBox("Here's some info about Class3s") End Select End Sub End Class 'End PlugInB
  2. Thanks, but the code that I quoted would appear in a plug-in to which I send X, and the plug-in decides what action to take depending on what type of X it has. So I don't see that I can use an interface as the topic suggests because the action can't really be encapsulated in the types of X - it's specified in the plug-in.
  3. Is there any way you can use Select Case for comparing objects on the basis of the "Is" operator? e.g to select from a range of possible types: Select Case X.GetType Case GetType(Class1) Case GetType(Class2) End Select This doesn't work because "=" is not defined for the Type Class.
  4. OK, I can now see something. You have a parent class and several types of child classes. All child classes inherit the parent. You have any number of interfaces. The parent class contains properties that match those of each interface, but does not implement any of them. Each child class can implement any number of the interfaces and does so by shadowing the relevant procedures of the parent class. That way each child class can be TypeOf any number of the interfaces, but all the code for those interfaces will be in the parent class. And maybe you can hide the parent methods that you don't want in the respective child classes. Is that the idea? This still doesn't use the mixin class though!
  5. Thanks, but I remain completely baffled. You seem to be saying that by declaring methods in the parent class (without those methods implementing anything) you can avoid having to implement methods of an interface which is implemented by the child class. Does the child class somehow specify that the methods it inherits from the Parent are being used to implement methods of an interface? If so, how? Do you say MyBase.getInt1 Implements MRequires.getInt? I don't think that works. I'm not using the mixin class because I haven't a clue what I'm meant to do with it! I have not achieved what I want to achieve. What I'd like to have is as I stated in my original post. In essence, getting: TypeOf(Shares) Is Securities = True TypeOf(Shares) = Debt = False TypeOf(Loan) = Securities = False TypeOf(Loan) = Debt = True TypeOf(Bonds) = Securities = True TypeOf(Bonds) = Debt = True without having to repeat a whole lot of code for implementing an interface in exactly the same way across a lot of bottom level classes.
  6. No it's not - the author of the article specifically states of the Parent class "This class must have all of the methods required of the MRequires interface, but it need not implement this interface.". That seems a bizarre thing to do and he doesn't offer any explanation for it. And what code am I supposed to put inside the Child class? Currently I'm not making any use of the mixin class.
  7. Can't get my head around this article at all. For instance he says "To implement the Child class we create a new Mixin object and save it.". Well in VB the only thing you implement is an interface, and the Child class is not an interface, so I've no idea what this means. Below is my attempt to convert the Java into VB. It defines a Child class which inherits from a Parent class and implements two interfaces. It also defines a Mixin class, but I don't understand what I'm supposed to do with that! Public Interface MRequires Function getInt() As Integer End Interface Public Interface MProvides Function func() End Interface Public Class mixin Implements MProvides Public Function func() As Object Implements MProvides.func Return 123 End Function Public Sub New(ByVal X As MRequires) 'What do I do with X? End Sub End Class Public Class Parent Public Function getInt() As Integer Return 77 End Function End Class Public Class Child Inherits Parent Implements MRequires Implements MProvides Public Function func() As Object Implements MProvides.func Return 123 End Function Public Function getInt1() As Integer Implements MRequires.getInt End Function End Class
  8. They seem quite useful to me. If you create a Boolean to store whether or not the value is set then you've got to remember what that Boolean is every time you want to use the variable. With a nullable variable you haven't, which is much simpler.
  9. Should have thought longer before posting. Just do: r = Nothing I note that Microsoft doesn't seem to use this facility itself, e.g. the SelectedIndex of a combobox is not a nullable type, so with no item selected it is -1, rather than there being no value.
  10. Declaring a nullable type in VB.net 2.0 and determining whether or not it has a value is easy: Dim r As Nullable(Of Long) MsgBox(r.HasValue) 'False r = 0 MsgBox(r.HasValue) 'True But is there a way to set r back to the state of having no value having given it one?
  11. It seems rather substandard to me. I'm already holding my breath for Visual Studio 2005 (of which I'm using the Beta Version, and that doesn't allow multiple inheritance) so I certainly won't be holding my breath for the version after that. Maybe I could do it with interfaces, but it would be a big inconvenience.
  12. If you want to have a class inherit from more than one other class you get a message from VB that only one Inherits statement is allowed in each class. But why? Suppose I have a Securities class and a Debt Class. A Loan Class would inherit Debt. A Shares Class would inherit Securities. A Bonds Class would inherit Debt and Securities. It seems a reasonable enough thing to want to do to me. I guess you have to be sure there's no conflict between properties in the Securities and the Debt class, but I'm sure that could be dealt with. Is there any decent workaround to this?
  13. Thanks. Have looked into this further. When you use such a variable you have to use square brackets too. Where you declare a variable as [Object], say, the variable will be taken to refer to the normal type of Object unless you define your own [Object] Class in which case it will be taken to refer to that. So you can use this to use restricted words as variable names or as class names. Apparently one reason for doing this is, if in a later version of VB, a variable or class name that you use becomes a keyword. Then if you've had the foresight to use square brackets, the code will continue to work. Can't think that many people would bother about that.
  14. I've noticed that you can enclose object types in square brackets when declaring them. What's that all about?
  15. Thanks. How could I store a description with each class and use Reflection to extract this?
  16. In VB6 I used the TypeLib Information dll (tlbinf32.dll) to find out about the classes contained in a plug-in Class Library. Is that still the best way to do it in .net?
  17. OK, thanks, seems to work. What I was thinking was that I needed to just draw what I was drawing in the MouseMove event and avoid triggering the paint event of the PictureBox, because I thought this would lead to flickering. But your code does trigger that event and there is no flickering. If I use the picturebox's CreateGraphics method then this seems to work just as well.
  18. I'm none the wiser. Where? And with what argument?
  19. I've looked and I'm sure it must be on here somewhere, but I can't find it. How do I persist an image in VB.net? Say I wanted to show an image that joined up all the points that a mouse had moved to. I can draw in the Paint event, but this is the MouseMove event, so how do I handle that? How do I store the previous image before drawing the next line on it?
  20. I'm using System.Windows.Forms.ToolStripButtons and setting the CheckOnClick property to True so that when they are pressed they become checked and this is displayed automatically. I'm using Windows Classic display style for my computer.
  21. Yes, I rather agree. If I go and buy another control, I've got to learn how to use that and then worry about distributing it and everything. It seems it's quite easy to owner draw controls in .net through the Paint event, so I may do that.
  22. Lovely Jubbly.
×
×
  • Create New...