Using The Shadowing And Delegate Methods?
May 8, 2009shadowing and delegate method?
View 8 Repliesshadowing and delegate method?
View 8 RepliesI'm in a project where it's pretty much my first time doing all the architecture myself,and I'm running into a frustrating situation. My architecture for forms seems to be correct from a heuristic perspective, but I don't think its implementation is correct.
My architecture is thus:
Base Class: OrderForm
Child Classes: PurchaseOrder, Invoice, Credit
[code].....
I have a method with a custom attribute that lists other methods in the same class that it can call. I'm passing the called method to another class function that will read the attribute and pick one of the methods named in the attribute and return it's delegate. I'm having a hard time figuring out how to do this with reflection or event if it is possible.
<AttributeUsage(AttributeTargets.Method, allowmultiple:=False)>
Public Class ExecuteSimiliar
Inherits System.Attribute
[Code]....
Suppose we got a form with some checkboxes. Each ckeckbox represents a method of the same class. Each method takes no arguments, returns no values. Is it possible using a delegate to loop through the checkboxes and run only the methods being checked?
View 4 RepliesIn C# adding event handler methods is very easy. You just type "object.event +=" and then press tab twice. Is there anything like this for VB projects? Note: This is for dynamically created controls or controls that are not declared WithEvents.
View 1 Repliesfrom the documentation we have this: Multicast Delegate: Represents a multicast delegate; that is, a delegate that can have more than one element in its invocation list.
so am i right to say that Multicast delegate is no different from a normal delegate other than the fact that it has arguments. so System.Action is a 'normal' delegate whereas System.Action(T)(Byval obj as T) is a multicast delegate?
I've created a Delegate that I intend to call Async.
[Code]...
Code:
Public Class SendPings
Shared Sub New()
AddHandler Post.Saved, AddressOf Post_Saved[code].....
I get a error" Method 'Private Shared Sub Ping(item As BlogEngine.Core.IPublishable, itemUrl As System.Uri)' does not have a signature compatible with delegate 'Delegate Sub WaitCallback(state As Object)'.
In VB.NET there is a keyword 'shadows'. Let's say I have a base class called 'Jedi' and a derived class called 'Yoda' which inherits from 'Jedi'. If I declare a method in 'Jedi' called 'ForcePush' and shadow that out in 'Yoda' then when calling the method on an instance of the 'Yoda' class, it will ignore the base class implementation and use the derived class' implementation. However if I have an instance of 'Yoda' that was declared originally as of type 'Jedi', i.e. Dim j as Jedi = new Yoda(), and called the 'ForcePush' method on the instance, it will use the Jedi implementation.
Now let's say I have an event that is called 'UsingForce' which is raised when the 'ForcePush' method is called, and I shadow the event out in the derived class (this is because 'Yoda' has an interface 'IForcePowers' that declares this event) and each class raises it's respective event.
If I have an instance of 'Yoda' that is declared as type 'Jedi' (like above) and I put an event handler on the 'UsingForce' event of 'Jedi', and then the 'ForcePush' method is called in the 'Yoda' class, will this event handler be reached?
I have a two windows forms classes, a base class and a derived class. The base class has an event handler which handles ValueChanged on some component. I have also written a different event handler for the same event on the derived class.
When I create an instance of the derived class and fire the event, I find that both event handlers run (the base class one and then the derived class one). But I want only the handler in the derived class to run.
Edit: Here is what the code looks like (can't post the actual code):
Public Class BaseForm
Inherits System.Windows.Forms.UserControl
(Windows Form Designer Generated Code)
[Code].....
It works, but doesn't save what I've changed it to. In the designer everything works fine. I can change the text and have it update on my button control. BUT once I run or rebuild in any way, the text property changes back to it's default value, in my case "Button Control"These are what I've tried, and I've tried all with both Shadows and Overrides - both with identical outcomes. So I've just indicated that with Shadows/Overrides.
vbnet
<DefaultValue("Button Control"), Browsable(True)> _ Public Shadows/Overrides Property Text As String Get Return MyBase.Text End Get Set(ByVal value As String) MyBase.Text = value Me.Invalidate() End Set End Property Private _Text As String = "Button Control" <DefaultValue("Button
[code]....
I have a couple of small classes to represent parts in a search filter. If the searched value equals NonValue the filter is supposed to do nothing. This is defined in a Base Class:
Private Class BaseFilter
Protected NonValue As Object
Protected sQueryStringBase As String = "AND {0} {1} {2} "[code]......
When I then create a StringFilter and check for allowed value:
Dim stf As New StringFilter()
stf.CheckNonValue(MyString)
I get a NullReferenceException (NonValue = Nothing) , when I expected the NonValue object to be String.Empty. Is this a bug in my code, or am I trying to achieve polymorphism in a wrong way?
I have created a new usercontrol. My usercontrol contains several other controls like labels, buttons and so on ...When I set the Font property of the usercontrol I want that font property value to propagate down to the child controls.
View 2 RepliesShadows vs. Overrides in VB.Net.What's the difference between shadowing a function in a base class in a subclass and overriding the same function? There is performance issues involved too?I know how to shadow and how to override in VB.net. My question is about when and why should I shadow a function instead override it and vice-versa.
View 2 RepliesThis is the original code in c#
public class CategoryRepository: RepositoryBase<Category>, ICategoryRepository
{
public CategoryRepository(IDatabaseFactory databaseFactory)
: base(databaseFactory)
[Code]...
Does anyone has an idea what i should change to let it work and let my UserRepository use the methods in RepositoryBase while implementing the IUserRepository?
I am working with a vb program, but there is something strange on one of my .vb code pagewhen i put the "dot" afther the object name its dont show the methods availables for this objectbut on other vb code pages i can see it. but in this one no.for exmaplethis is a piece of code: Dim sb As New StringBuilder()
View 3 RepliesI am not sure how clear my question is by the title, but I am trying to make Class methods instead of Instance methods in Visual Basic that way I don't have to waste memory and code creating temporary objects to execute methods that don't need instance variables.
I am not sure if you can do that in VB but I know you can in Objective-C by using either a "+" or "-" sign in front of the method declaration. And in C++ (at least I think, I can't remember) you put the static keyword or const keyword in front of the function.How would I do this in VB if it is possible? Or should I just make a separate set of functions that are not members of a class?
I am trying to write a VB.NET alternative to a C# anonymous function.I wish to call Threading.SynchronizationContext.Current.Send which expects a delegate of type Threading.SendOrPostCallback to be passed to it. The background is here, but because I wish to both pass in a string to MessageBox.Show and also capture the DialogResult I need to define another delegate within. I am struggling with the VB.NET syntax, both from the traditional delegate style, and lambda functions.My go at the traditional syntax is below, but I have gut feeling it should be much simpler than this:
Private Sub CollectMesssageBoxResultFromUserAsDelegate(ByVal messageToShow As String, ByRef wasCanceled As Boolean)
wasCanceled = False
[code].....
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim someproc As Process
[Code]...
While reading this threadthe code sample there came from MSDN, which was used to demonstrate the use of a delegate. I know what Delegates are. And I know how they work when it comes to things like crossing threads and even sinks.... how ever, the sample given is a simplecontrived example, and I'm wondering why/when would I use a delegate in this situation? Or in any situation? In my head, it seems it would have been easier/cleaner to call the function pointed to directly...
View 18 RepliesI heard once that .net introduced an already defined delegate with no parameter that we could use instead of creating one.
View 1 RepliesI came across a snippet of C# code which is very useful. I am trying to convert it to VB.NET, but can't seem to.
timer.Tick += delegate { panel.Children.Add(source); timer.Stop(); };
Is it possible to translate this to something similar in VB?
I have below code in C#:
[Code]...
I'm having trouble converting a C# delegate to VB.NET.
How can this be done?
public MainForm()
{
InitializeComponent();
_twain = new Twain(new WinFormsWindowMessageHook(this));
_twain.TransferImage += delegate(Object sender, TransferImageEventArgs args)
[Code]...
how can I convert the following code from C# to VB without exposing "variable" as global variable.
[Code]...
I'm in the process of converting some existing code to VB. However, I'm running into a bit of a snag. It seems that in C#, a delegate can have a return value, but not so in VB. So my question is, how would I convert the following VB code to handle this?.[code]
View 3 Repliesim developing a way of calculationg differentil equations in VB 2008 using the 4th order ruge-kutta method. I pursched a book by Jack Xu called "Practical WPF Graphics programming".
[Code]...
how this is written in VB.NET? This was an example I found on [URL]
ThreadPool.QueueUserWorkItem(delegate
{
var channelFactory = new ChannelFactory<ISimpleService>("*");
var simpleService = channelFactory.CreateChannel();
var asyncResult = simpleService.BeginGetGreeting("Daniel", null, null);
[code]....
I am using this delegate to invoke my methode:
[Code]...
for few solutions it work outs well but not for the following code. I find an error when executing the following code. I find an error :
ErrorMethod 'Public Sub test()' does not have the same signature as delegate 'Delegate Sub DataRowChangeEventHandler(sender As Object, e As System.Data.DataRowChangeEventArgs)'.C:UsersKashifDocumentsVisual Studio
[code].....